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')),
));
Related
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
));
I am trying to set the text inside the lengend tag within the following code:
$element->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('legend' => 'HtmlTag'), array('tag' => 'legend', 'placement' => 'prepend')),
array(array('fieldset' => 'HtmlTag'), array('tag' => 'fieldset')),
));
The following is generated:
<fieldset>
<legend></legend>
</fieldset>
and I would like:
<fieldset>
<legend>Blah</legend>
</fieldset>
Any help would be appreciated!
Update:
Using Regis's answer, I implemented this like so:
$decorator = new Zend_Form_Decorator_Fieldset();
$decorator->setLegend("legend");
$element->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array($decorator),
array(array('div' => 'HtmlTag'), array('tag' => 'div')),
));
you can try in this different way:
$decorator = new Zend_Form_Decorator_Fieldset();
$decorator->setLegend("legend");
$element->addDecorators(array($decorator));
Maybe somebody knows. How to wrap Zend_Form_Element_Radio including Label of whole stack of radio inputs (with input labels).
public $radioDecorators = array(
'ViewHelper',
array('Description',array('tag'=>'div','class'=>'','placement' => 'prepend')),
array('Errors',array('class'=>'error_message_show','placement' => 'prepend')),
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
array('label', array('class'=>'label_text','placement' => 'prepend')),
array(array('rows' => 'HtmlTag'), array('tag' => 'div', 'class' => 'radio')),
);
$offer_type = new Zend_Form_Element_Radio('offer_type', array(
'label' => 'Label I'd like to wrap with inputs', //Label to wrap
'required' => true,
'description' => '',
'decorators' => $this->radioDecorators,
'multioptions' => array (
'standard' => 'standard',
'premium' => 'premium',
),
));
$this->addElement($offer_type);
Above example didn's solve my as it wraps only several inputs label's.
I think I know what you're after and if so, you're in luck as I just had to do this the other day.
The standard ZF multi-option element separates each "option" using the separator property (defaults to <br /> for radio and newline for select). This is fine for <option> elements but pretty shoddy for a collection of radio buttons.
The solution is to
Add HtmlTag decorator(s) to the element, wrapping the content
Set the separator to close and re-open the HtmlTag
For example, here's a solution to wrap the collection of inputs in an unordered list
$offer_type = new Zend_Form_Element_Radio('offer_type', array(
'separator' => '</li><li>',
'decorators' => array(
'ViewHelper',
array(array('liWrapper' => 'HtmlTag'), array('tag' => 'li')),
array(array('ulWrapper' => 'HtmlTag'), array('tag' => 'ul')),
// the rest
)
));
The alternative is to write your own view helper. Creating your own version of formRadio should be pretty easy.
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.
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