Zend Framework Checkbox Decorators - php

What I am trying to accomplish is to have checkbox labels display after checkbox input fields (to the right of them).
I am using these decorators now:
private $checkboxDecorators = array(
Label,
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'checkbox')),
'ViewHelper',
array(array('row' => 'HtmlTag'), array('tag' => 'li')),
);
I have tried switching the Label and ViewHelper decorators but that did nothing. Any suggestions?

$this->getElement('elementId')->addDecorator('Label', array('placement' => 'APPEND'))
the placement option can take APPEND or PREPEND as value

I know that is an older question, but you can also use
$element->getDecorator('label')->setOption('placement', 'APPEND');
if it is an already created element with an existing decorator

Related

Zend Form Checkbox Element customization

I have a zend form with some element on, including a check box.
It looks normal :
checkbox label []
I would like to add a link to the right making it look like this:
checkbox label [] thelink
I've tried the following, but instead of aligning horizontaly the description with the checkbox it puts it under it :
$boolean->setDescription('desc');
$boolean->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
));
I'm a begginer with Zend Forms. Any idea how could i implement this?
Thank you
Got it!
Here's how i did it:
$boolean->setDescription('description');
$boolean->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
array('Description', array('escape' => false, 'tag' => '', 'placement' => 'append')),
));

Zfdatagrid 0.8 adding elements to CRUD-forms

I'm using ZendFramework 1.11 and Zfdatagrid 0.8.
I've created a grid and a CRUD-form using my own db-model as source. Then I added some extra elements to the CRUD-form like this:
$element = new Zend_Form_Element('element', array('label'=>'new element:'));
$grid->getForm(1)->addElement($element);
The new element is added to the form properly, but whereas all other form elements are within a table, the added element is placed as a list element above the actual form. Instead of this, i would like to have the added element as a part of the table to achieve a proper look of the form. Has anybody faced this issue before or an idea of how to do it? Any help is appreciated!
Thanks in advance!
$elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td', 'class' => 'form_label')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
$this->_grid->getForm(1)->addElement('select', 'group', array(
'required' => true,
'value' => 'rtrt',
'label' => 'Group',
'multiOptions' => $list_contactgroup,
'order' => 5, 'decorators' => $elementDecorators
));

Need help understanding Zend_Form decorator rendering

I have
$title = new Zend_Form_Element_Text('title', array('size'=>'20'));
$title->setLabel('Title')
->addValidator('NotEmpty')
->setDecoratorsarray(
'ViewHelper',
array(array('dataz'=>'HtmlTag'), array('tag' => 'div', 'class' => 'input')),
array('Label', array('tag' => 'td')),
array('row'=>'HtmlTag', array('tag' => 'div','class'=>'element')),
);
I need help understanding how to set parameters.
Why do we first point ViewHelper not the end?
Why 2 times html tag between the label?
If I change their position, it doesn't render correctly.
Why only in last option would you want to warp elements (label and input) in the div with class "element"? If I only define HtmlTag once it warps only input elements together, not both label and input.
How do I wrap both elements?
$title = new Zend_Form_Element_Text('title', array('size'=>'20'));
$title->setLabel('Title')
->addValidator('NotEmpty')
->setDecorators(array(
'ViewHelper',
array(array('dataz'=>'HtmlTag'), array('tag' => 'div', 'class' => 'input')),
array('Label', array('tag' => 'td')),
array('row'=>'HtmlTag', array('tag' => 'div','class'=>'element')),
));
Sorry it was some mistake in code.

Problem with addDisplayGroup in the Zend Form

I have a form same the following code:
public function init(){
$id=$this->createElement('hidden','cf_id');
$id->setDecorators($this->elementDecorators);
$id->setOrder(1);
$this->addElement($id);
$firstName=$this->createElement('text','firstName');
$firstName->setDecorators($this->elementDecorators);
$firstName->setLabel('name :');
$firstName->setOrder(2);
$firstName->setAttrib('class','textbox');
$firstName->setAttrib('disabled',true);
$this->addElement($firstName);
$lastname=$this->createElement('text','family');
$lastname->setLabel(' family:');
$lastname->setDecorators($this->elementDecorators);
$lastname->setOrder(3);
$lastname->setAttrib('class','textbox');
$lastname->setAttrib('disabled',true);
$this->addElement($lastname);
$this->addElement('button', 'cancel', array(
'label' => 'Cancel Button',
'class'=>'button',
'decorators' => array(
'ViewHelper',
),
));
$this->addElement('button', 'submit', array(
'label' => 'Submit Button',
'class'=>'button',
'decorators' => array(
'ViewHelper',
),
));
$this->addDisplayGroup(array('submit', 'cancel',), 'submitButtons', array(
'order'=>4,
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'element')),
),
));
}
In this form there are some elements and two buttons. In display page, the buttons are shown above form before other elements.
How can I put these buttons at the bottom of all elemnts?
Thanks.
Zend renders the elements in the order in which they are added via the addElements() method. So, I would add them like this:
$this->addElements(array(all elements you want to appear first in top-down order));
$this->addElements(array(button elements));
Then use CSS in the view to manipulate their locations.
Hope that helps.
add them before other elements ;-)
Add your other fields to another display group, defined before the display group you already have. You will probably need to adjust the decorators some-what.

decorating Zend_Form_Element_MultiCheckbox in a unordered list

I need to decorate to Zend_Form_Element_MultiCheckbox into a unordered list, I can get each item surround by <li>, by setting setSeparator to </li><li> and the HtmlTag tag to <li>
I just get find anything to set the <ul> around this list, anyone able to point me in the right direction?
Thanks for reading (My code is below)
$interests = new Zend_Form_Element_MultiCheckbox('foo');
$interests->setSeparator('</li><li>');
foreach ($interestsTable->findForSelect() as $interest) { // For earch interest add an option
$interests->addMultiOption($interest->interest_id, $interest->interest);
}
// Decorate the interests
$interests->setDecorators(array(
array('ViewHelper'),
array('label', array(
'tag' => 'span' )),
array('HtmlTag', array(
'tag' => 'li', 'class' => 'interestOption'))
));
I can't give you any code that will work off the top of my head, but, from reading the docs, it's clear that you can re-use decorators as many times as you need to. You just need to specify a new name for them.
Look at: http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.decorators, specifically the section titled "Using Multiple Decorators of the Same Type".
Based on that, the below might work (but I haven't tested it, it could be in the wrong order or anything):
$interests->setDecorators(
array(
array('ViewHelper'),
array('label', array( 'tag' => 'span' )),
array('HtmlTag', array( 'tag' => 'li', 'class' => 'interestOption')),
array(
'decorator' => array('LiTag' => 'HtmlTag'),
'options' => array('tag' => 'ul')
)
)
);

Categories