|
I've been trying without any luck to add HTML to a Zend_Form. I started out with just trying to add a font to a label for one of the fields in my form: $this->addElement('select','types', array( 'label' => 'What type of home do you live in:', 'required' => true, 'multiOptions' => array( 'Existing Home' => 'Existing Home', 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', 'Apartment' => 'Apartment',),)); but when I add the html, Zend just renders it as text. I've read something about adding an esacape=>false to $decorators element or something, but I really am not sure how to do so. I would really appreciate some guidance on this, as I can't seem to find a straightforward example. Thanks, Thomas List |
|
Thomas,
You would either have to create a decorator or you can echo out all the form elements in the view with the label turned off. An example with the label decorator turned off: $this->email ->setRequired(true) ->addFilter('StripTags') ->addValidator('EmailAddress') ->*removeDecorator('Label');* *View:* <table> <tr> <td>YOUR LABEL HERE</td> <td><?php echo $this->form->email?></td> </tr> </table> You could also just add a class to those elements and do your styling in CSS. $this->email ->setOptions(array('class' => 'CLASS_NAME_HERE')) ->setRequired(true) ->addFilter('StripTags') ->addValidator('EmailAddress') ->removeDecorator('Label'); Tully Rankin PHP Developer www.tullyrankin.com On 10/22/2010 12:53 PM, Thomas List wrote: > I've been trying without any luck to add HTML to a Zend_Form. I started out with just trying to add a font to a label for one of the fields in my form: > > $this->addElement('select','types', array( > 'label' => 'What type of home do you live in:', > 'required' => true, > 'multiOptions' => array( 'Existing Home' => 'Existing Home', 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', 'Apartment' => 'Apartment',),)); > > > but when I add the html, Zend just renders it as text. I've read something about adding an esacape=>false to $decorators element or something, but I really am not sure how to do so. I would really appreciate some guidance on this, as I can't seem to find a straightforward example. > > Thanks, > Thomas List > > |
|
In reply to this post by Thomas List
The escape is used the same way as label, required and multioption:
$this->addElement('select', 'types', array( 'label' => 'Some <span>html</span> label', 'required' => true, 'escape' => false, 'multiOptions => array(...) ); Regards, Jurian -- Jurian Sluiman CTO Soflomo V.O.F. http://soflomo.com On Friday 22 Oct 2010 21:53:59 Thomas List wrote: > I've been trying without any luck to add HTML to a Zend_Form. I started > out with just trying to add a font to a label for one of the fields in my > form: > > $this->addElement('select','types', array( > 'label' => 'What type of home do you live in:', > 'required' => true, > 'multiOptions' => array( 'Existing Home' => 'Existing Home', > 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', > 'Apartment' => 'Apartment',),)); > > > but when I add the html, Zend just renders it as text. I've read something > about adding an esacape=>false to $decorators element or something, but I > really am not sure how to do so. I would really appreciate some guidance > on this, as I can't seem to find a straightforward example. > > Thanks, > Thomas List |
|
It may be sacriligious to those who really love to do everything
programmatically, but I think there is a lot to be said for going a sort of Middle Way and writing view scripts that render Zend_Form elements semi-manually, as it were. I sometimes do things like the following. It might be ugly, but it saves me from the torture of mastering all the nuances of decorators etc and gets the job done: <dl> <?= $I->mobile?> <?= $I->home ?> <?= $I->fax?> <?= $P->office_phone->renderLabel()?> <dd><?= $P->office_phone->renderViewHelper()?><?php if ($P->office_phone_ext) : ?> <?=$this->formLabel('person_office_phone_ext','Ext')?> <?= $P->office_phone_ext->renderViewHelper()?><?php endif; ?></dd> <?= $I->address1?> <?= $I->address2?> <dt>City</dt> <dd><?= $I->city->renderViewHelper()?> State <?= $I->state->renderViewHelper()?></dd> <?= $I->zip?> </dl> On Friday 22 Oct 2010 21:53:59 Thomas List wrote: > I've been trying without any luck to add HTML to a Zend_Form. I started > out with just trying to add a font to a label for one of the fields in my > form: > > $this->addElement('select','types', array( > 'label' => 'What type of home do you live in:', > 'required' => true, > 'multiOptions' => array( 'Existing Home' => 'Existing Home', > 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', > 'Apartment' => 'Apartment',),)); > > > but when I add the html, Zend just renders it as text. I've read > about adding an esacape=>false to $decorators element or something, but I > really am not sure how to do so. I would really appreciate some guidance > on this, as I can't seem to find a straightforward example. > > Thanks, > Thomas List -- David Mintz http://davidmintz.org/ It ain't over: http://www.healthcare-now.org/ |
|
Hello David,
> It may be sacriligious to those who really love to do everything > programmatically, but I think there is a lot to be said for going a sort of > Middle Way and writing view scripts that render Zend_Form elements > semi-manually, as it were. I sometimes do things like the following. It > might be ugly, but it saves me from the torture of mastering all the nuances > of decorators etc and gets the job done: > > <dl> > <?= $I->mobile?> > <?= $I->home ?> > <?= $I->fax?> > <?= $P->office_phone->renderLabel()?> > <dd><?= $P->office_phone->renderViewHelper()?><?php if > ($P->office_phone_ext) : ?> > <?=$this->formLabel('person_office_phone_ext','Ext')?> <?= > $P->office_phone_ext->renderViewHelper()?><?php endif; ?></dd> > <?= $I->address1?> > <?= $I->address2?> > <dt>City</dt> > <dd><?= $I->city->renderViewHelper()?> State <?= > $I->state->renderViewHelper()?></dd> > <?= $I->zip?> > </dl> Sure - it might get the job done, but since you're not following Zend Framework Code Conventions, I wouldn't even bother considering to hire you if I were the owner of a company that is looking for a developer. Best regards, Andreas |
|
Way to go on missing the point.
Something tells me that he has no interest at all in being hired by you. I don't think I would either. Last thing I would want would be a client telling me what coding style to use for code I write for other people... Cheers, David |
|
> Way to go on missing the point.
> > Something tells me that he has no interest at all in being hired by you. I > don't think I would either. Last thing I would want would be a client > telling me what coding style to use for code I write for other people... Right, but writing quality code or not can make the difference between having clients at all - or not. Best regards, Andreas |
|
Administrator
|
In reply to this post by localheinz
-- Andreas Möller <[hidden email]> wrote
(on Wednesday, 27 October 2010, 10:14 AM +0200): > Sure - it might get the job done, but since you're not following Zend > Framework Code Conventions, I wouldn't even bother considering to hire > you if I were the owner of a company that is looking for a developer. Please, try to keep the comments constructive. Comments like the one above do nothing to aid the person asking the original question, and instead polarize the discussion. Sure, the code sample may have used short tags -- but ZF recommended short tags in view scripts for quite some time. And, again, this was a _view_ script -- markup generally follows very different rules than library or application code. Additionally, different organizations and projects will have their own requirements for coding standards -- regardless of our own personal opinions on the matter, it's best to simply evaluate the code, and give pointers for areas of improvement in the _logic_. Again, if you have nothing constructive to add to a discussion, please refrain from posting. -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
In reply to this post by Thomas List
Thomas,
I'm having the same problem. I cannot use 'escape' => falsewhen using addElement the way you are using it. Instead, I'm doing the following: $emailElement = new Zend_Form_Element_Text('email');
$emailElement -> setLabel('<span class="req">*</span>Your email address:')
-> setRequired(true)
-> setValidators(array('EmailAddress'))
-> setFilters(array('StringTrim'))
-> setDescription('')
-> setDecorators(array(
'ViewHelper',
array('Description', array('escape' => false, 'tag' => false)),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt', 'escape' => false)),
'Errors',
));
$this->addElement($emailElement);
I'm very new to this, so I'm sure that's not the most elegant solution, but it seems to work. |
|
In reply to this post by David Mintz-3
I absolutely agree with David here. Decorators are technically well
designed and fine... but they are sometimes just a way too heavy weapon for a small view level bells and whistles. At least for my taste. m. On Tue, Oct 26, 2010 at 3:45 PM, David Mintz <[hidden email]> wrote: > It may be sacriligious to those who really love to do everything > programmatically, but I think there is a lot to be said for going a sort of > Middle Way and writing view scripts that render Zend_Form elements > semi-manually, as it were. I sometimes do things like the following. It > might be ugly, but it saves me from the torture of mastering all the nuances > of decorators etc and gets the job done: > > <dl> > <?= $I->mobile?> > <?= $I->home ?> > <?= $I->fax?> > <?= $P->office_phone->renderLabel()?> > <dd><?= $P->office_phone->renderViewHelper()?><?php if > ($P->office_phone_ext) : ?> > <?=$this->formLabel('person_office_phone_ext','Ext')?> <?= > $P->office_phone_ext->renderViewHelper()?><?php endif; ?></dd> > <?= $I->address1?> > <?= $I->address2?> > <dt>City</dt> > <dd><?= $I->city->renderViewHelper()?> State <?= > $I->state->renderViewHelper()?></dd> > <?= $I->zip?> > </dl> > > On Friday 22 Oct 2010 21:53:59 Thomas List wrote: >> I've been trying without any luck to add HTML to a Zend_Form. I started >> out with just trying to add a font to a label for one of the fields in my >> form: >> >> $this->addElement('select','types', array( >> 'label' => 'What type of home do you live in:', >> 'required' => true, >> 'multiOptions' => array( 'Existing Home' => 'Existing Home', >> 'New Construction' => 'New Construction', 'Condominium' => 'Condominium', >> 'Apartment' => 'Apartment',),)); >> >> >> but when I add the html, Zend just renders it as text. I've read > something >> about adding an esacape=>false to $decorators element or something, but I >> really am not sure how to do so. I would really appreciate some guidance >> on this, as I can't seem to find a straightforward example. >> >> Thanks, >> Thomas List > > > -- > David Mintz > http://davidmintz.org/ > It ain't over: > http://www.healthcare-now.org/ > |
| Powered by Nabble | Edit this page |
