Archives for Adrian Nuta blog

non-input Zend Form Element

Simple case : let’s say you make a form for user to register . You have an email field , right ? Ok , now when the user is logged you have a page where he can modify password and other settings . You should normally want to display the email too , but you don’t want to be editable ( because emails should unique etc. ) .You could show the email separated from the form , but you don’t want that , you want it to be in the same area with the other fields .
One simple approach is to create a “dummy” element , one that can be populated by the populate() function , but actually don’t have an <input> . The way is to create an element that extends Zend_Form_Element or Zend_Form_Element_Xhtml which uses formNote helper . Normally this helper is used by hidden elements ( it’s a dead simple helper , you can check the source in Zend/View/Helper) , but you can use it in this case too :

1
2
3
4
class App_Form_Element_Xhtml extends Zend_Form_Element_Xhtml
{
public $helper = 'formNote';
}

Now ,you will proubably extend your form when editing ( I use a Base form with the fields and for Edit/Register I extend it with new ones ) . To get the email displayed , you need first to remove the email element ( text type ) and replace it with this one :

1
2
3
4
5
6
7
$this->removeElement('email');
$fakeEmail = new App_Form_Element_Xhtml('email',array(
                 'required' => false,
                'ignore'=> true,
		'label' => 'Email : ',
		));
$this->addElement($fakeEmail);

You need to add ignore to be true , otherwise $form->getValues() will return you a “” value form the email – this can be fixed by declaring getValue and setValue functions for the element , but setting ignore works too .
The last step is to re-order . If the email is the first you can use $fakeEmail->setOrder(-1) before adding .

Eclipse , xdebug , remote system

This morning I had nothing better to do ( actually I had , but … ) so I thought “let’s try xdebug” . I’m working remote on a EC2 instance using Eclipse PDT . Installing xdebug is pretty easy , apt-get install php5-xdebug or something like that ( on debians) , you need to edit a .ini file then you create a debug profile in eclipse ( bla bla bla there’re a lot of tutorials about it ) .

Hit debug buton annnndd ….. “launching: waiting for xdebug session” . Wtf … doesn’t work .

Gogled a bit more , found that you should have the xdebug option xdebug.idekey to be the same with XDEBUG_SESSION_START used by the IDE . IN this case it’s ECLIPSE_DBGP . Netbeans eg. have netbeans-xdebug I think . Well, you can set it to whatever .

Hit button annndd … “launching: waiting for xdebug session” . Wtf … doesn’t work .

I remember I used xdebug some time ago , but I was running locally . So what could it be ? Well xdebug to help you need a remote address . By default is localhost . If you work remote , you should have instead of localhost your IP . Well , if you have a public IP , lucky you , but I bet you don’t have .

What to do ? SSH tunnel . You can do it . OR you could use the built-in option PDT have :)