addDisplayGroup 1:
$this->addDisplayGroup(DATEFROM,ELEM_DATETO),
'Date', array('order' => 4,
'decorators' => array('FormElements',
array(array('openinnerdiv' => 'HtmlTag'),
array('tag' => 'div', 'id'=>'date_to_from','name'=>'date_to_from','class'=>'date_to_from')),
array(array('opendiv' => 'HtmlTag'),
array('tag' => 'div','id'=>'date' ))
),
)
);
addDisplayGroup 2:
$this->addDisplayGroup(array('AddBlock','Add','AddDate','ORDERID','COUNTRYCODE','DATEFROM','DATETO','AGE','GENDER','LIST','CAMERA'),
'queryblockfld_1',array('order' => 4,
'decorators' => array('FormElements',
array(array('openinnerdiv' => 'HtmlTag'),
array('tag' => 'div', 'id'=>'queryblockfld_1','name'=>'queryblockfld','class'=>'queryblockfld')),
array(array('opendiv' => 'HtmlTag'),
array('tag' => 'div','id'=>'queryblock' ))
),
)
);
I want to Add addDisplayGroup1 to addDisplayGroup 2. Can any one help me in this.?
After a long research in Web I found the answer for my own question:
$this->addDisplayGroup(array('DATEFROM','DATETO'),
'contact',array('legend' => 'Contact Information'));
$from_to = $this->getDisplayGroup('contact');
$from_to->setDecorators(array('FormElements',
array(array('openinnerdiv' => 'HtmlTag'),
array('tag' => 'div', 'id'=>'date_1','name'=>'date_1','class'=>'date_1','openOnly'=>true)),
array(array('opendiv6' => 'HtmlTag'),
array('tag' => 'div','id'=>'blockfld_1','class'=>'blockfld','openOnly'=>true)),
array(array('opendiv' => 'HtmlTag'),
array('tag' => 'div','id'=>'block','openOnly'=>true)),
));
$this->addDisplayGroup(array('AddBlock','Add','AddDate','NUMBERPLATE','COUNTRYCODE','NODE','CAMERA','NODELIST','NODECAMERA'),
'pass',array('legend' => 'Password'));
$pass = $this->getDisplayGroup('pass');
$pass->setDecorators(array(
'FormElements',
array('HtmlTag',array('tag'=>'div','closeOnly'=>true))
));
I just modified for the answer so some small mistakes will be there kindly correct it.
Related
I have a Zend form with two buttons, Submit and Reset. See the below form code.
$submit = $this->CreateElement('submit','submit')
->setLabel('SUBMIT');
$submit->setDecorators(
array('ViewHelper',
'Description',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td',
'colspan' => '2',
'align' => 'center')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr',
'closeOnly' => 'true')
)
)
);
$reset = $this->CreateElement('reset', 'reset')
->setLabel('RESET');
$reset->setDecorators(
array('ViewHelper',
'Description',
'Errors',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr',
'closeOnly' => 'true')
)
)
);
This is my form output image:
This reset and submit button is an ugly view. I don't like this view.
How do I set the reset and submit button in the same line?
Use valign="top" for both buttons.
I have the problem, that the following Zend Form throws an error.
The problem is the "file"-element and using setElementDecorators.
class Products_AddForm extends Zend_Form
{
function init() {
// other form elements...
$uploadElement = new Zend_Form_Element_File('Excel');
$uploadElement->setLabel('Excel');
$this->addElement($uploadElement);
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'th')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
}
}
This throws an error.
(Warning: Exception caught by form: No file decorator found... unable to render file element Stack Trace: #0 )
Adding $uploadElement->addDecorator('File'); at the end after the SetElementDecorators will work, but this will give me the file element twice!
Can anybody help, please?
TIA
Matt
The File element requires it's own decorator - Zend_Form_Decorator_File.
$this->setElementDecorators(array(
'File',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'th')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
[edit]
Have just noticed that you are also using other form elements.
After your original code, add:
$this->getElement('Excel')->setDecorators(
array(
'File',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'th')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
)
);
That way, ViewHelper is added to all other elements, and for your File element File is used instead.
I have the following piece of code,
Under myClass , i have set decorators variable,
public $testDecorators = array(
'ViewHelper',
'Errors',
array('Description', array('escape' => false, 'tag' => '', 'placement' => 'append')),
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'itemR')),
array('Label', array('tag' => 'div', 'class' => 'itemL')
),
array('HtmlTag', array('tag' => 'div', 'class' => 'itemcontent'))
);
Under CreateForm function,
....
$cover_image = new Zend_Form_Element_File('cover_test', array(
'label' => 'Cover Test:',
'value' => '',
'class' => 'test',
'tabindex' => '5',
'required' => false,
'filters' => array('StringTrim'),
'decorators' => $this->testDecorators,
));
....
When i use this decorators, nothing is displaying in my form, if commented that 'decorators' => $this->testDecorators, form is coming fine with default dd tag, Kindly help me
The file element must include the 'File' decorator, usually in place of the ViewHelper decorator. So try this instead:
public $testDecorators = array(
'File',
'Errors',
array('Description', array('escape' => false, 'tag' => '', 'placement' => 'append')),
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'itemR')),
array('Label', array('tag' => 'div', 'class' => 'itemL'),
array('HtmlTag', array('tag' => 'div', 'class' => 'itemcontent'))
);
Have you looked at what $cover_image->getDecorators() shows?
Also, is this one in the middle correct:
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'itemR')),
should it not be:
array('HtmlTag', array('tag' => 'div', 'class' => 'itemR')),
as the last one is?
I found code that would change the standard dt and dd tags to table tags for a Zend_Form_Element. Here is the code I used:
$element->setDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td', 'class' => 'rightAlign')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
But this puts the class name 'rightAlign' on the label tag instead of the td. I can't seem to wrap my head around these custom decorators so can anyone tell me how to get the class name 'rightAlign' on the td surrounding the label?
Just add one more decorator
$element->setDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
'Label',
array(array('labelWrap' => 'HtmlTag'), array('tag' => 'td', 'class' => 'rightAlign')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label',array('requiredSuffix' => ' * ')),
array(array('labelWrap' => 'HtmlTag'), array('tag' => 'td', 'align' => 'right')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
will add the required suffix ;)
i created a form that it decorates as table form
its my code for decorates
$this->setElementDecorators(array(
'ViewHelper',
'Errors'
array(array('data'=>'HtmlTag'),
array('tag'=>'td','class'=>'element')),
array('Label',array('tag'=>'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr')),
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag',array('tag'=>'table')),
'Form'
));
it works correctly,
now i wana errors message decorates too
what do i change my code?
Here is a rather complex way of doing it. I have added classes to the decorators too so you can style them unlike your example.
// To be assigned at the beginning of your form class.
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
array('Label', array('tag' => 'td','class'=>'taR')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
);
$this->addElement('ValidationTextBox', 'name', array(
'decorators' => $this->elementDecorators,
'validators' => array(
array('regex', false,'/^[a-zA-Z ]+$/')
),
'label' => $this->translator->translate ( 'Name' ) . ' : ',
'required' => true,
'trim' => true,
'propercase' => true,
'regExp' => '[a-zA-Z ]+',
'invalidMessage' => $this->translator->translate ( 'Name - Must be alpha numeric.' )
)
);
If you want to show all erros grouped in one place you should remove the Error decorator from each element and then add to you form the formErrors decorator. Here is an example from How to remove Zend Form error messages?
$form->setDecorators(array(
'FormElements',
new Zend_Form_Decorator_FormErrors(array
(
'ignoreSubForms' => true,
'markupElementLabelEnd' => '</b>',
'markupElementLabelStart' => '<b>',
'markupListEnd' => '</div>',
'markupListItemEnd' => '</span>',
'markupListItemStart' => '<span>',
'markupListStart' => '<div id="Form_Errors">'
)
),
'Form'
));