zend-form

Zend Framework: Working with Form elements in array notation

情到浓时终转凉″ 提交于 2019-11-27 23:30:03
问题 I would like to be able to add a hidden form field using array notation to my form. I can do this with HTML like this: <input type="hidden" name="contacts[]" value="123" /> <input type="hidden" name="contacts[]" value="456" /> When the form gets submitted, the $_POST array will contain the hidden element values grouped as an array: array( 'contacts' => array( 0 => '123' 1 => '456' ) ) I can add a hidden element to my form, and specify array notation like this: $form->addElement('hidden',

Zend Framework 2 - Removed form element causes validation to fail

…衆ロ難τιáo~ 提交于 2019-11-27 23:15:52
I use a certain form in several places. In one of them I need to ignore a form element which I set programmatically after the validation. Because it's just an exception I don't want to create a new form. So I thought, I just remove this element in the controller like: $myForm->remove('myElement'); The problem is that the form now won't validate. I don't get any errors but the $myForm->isValid() just returns an empty value. Any ideas what I might be doing wrong? Thanks! Ok, finally I found a solution ! You can define a ValidationGroup which allows you to set the attributes you'd like to

Display Zend_Form_Element_Radio on one line

不想你离开。 提交于 2019-11-27 22:53:19
The radio buttons in Zend Framework are displayed in a column (one option per line). How can I remove the br tag from the markup so that all radio options stay in one line? My decorators are: private $radioDecorators = array( 'Label', 'ViewHelper', array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'radio')), array(array('row' => 'HtmlTag'), array('tag' => 'li')), ); Edward Dale You need to call the setSeparator method on the Zend_Form_Element_Radio object, passing it ''. Here's an example from here : <?php class CustomForm extends Zend_Form { public function init() { $this-

Zend Framework - Set 'selected' value in select box dropdown list

霸气de小男生 提交于 2019-11-27 22:00:41
I am adding a select element to a Zend_Form instance as follows: $user = $form->createElement('select','user')->setLabel('User: ')->setRequired(true); foreach($users as $u) { if($selected == $u->id) { $user->addMultiOption($u->id,$u->firstname.' '.$u->lastname); //*** some way of setting a selected option? selected="selected" } else $user->addMultiOption($u->id,$u->firstname.' '.$u->lastname); } I have been searching the docs but cannot find a simple way of pre-setting an option of the select element to 'selected'. I've just worked out how to do it. You have to use the setValue() method of the

How To Remove All DtDdWrappers and Labels on Zend Form Elements

十年热恋 提交于 2019-11-27 20:49:09
I know I can remove the extra stuff from each element individually like so $button ->removeDecorator('DtDdWrapper') ->removeDecorator('HtmlTag') ->removeDecorator('Label'); I was wondering if I can achieve the same for all my elements in a zend form? And how does one remove the dl wrapping the form? Markus, here is a solution that I use that seems to work well, hopefully it will be suitable for you. First, in order to render the form with no <dl> tag, we need to set the decorators on form object itself. From inside a class extending Zend_Form, you would call Zend_Form->setDecorators() passing

Zend File Upload and Element Decorators

穿精又带淫゛_ 提交于 2019-11-27 16:08:47
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:

Zend_Form - Array based elements?

两盒软妹~` 提交于 2019-11-27 14:02:10
Using Zend_Form, how would I create form elements like this: <input type="text" name="element[1]" value="" /> <input type="text" name="element[2]" value="" /> // etc... Stefan Gehrig You can either use subforms: $form = new Zend_Form(); $subForm = new Zend_Form_SubForm(); $subForm->addElement('Text', '1') ->addElement('Text', '2'); $form->addSubForm($subForm, 'element'); Or you should also be able to use setBelongsTo() on the form elements (untested): $form = new Zend_Form(); $form->addElement('Text', '1', array('belongsTo' => 'element')) ->addElement('Text', '2', array('belongsTo' => 'element

File Upload using zend framework 1.7.4

混江龙づ霸主 提交于 2019-11-27 12:52:06
问题 I am trying to upload a file using Zend Framework 1.7.4, but have not been successful. I have read Akrabat's tutorial, which was helpful but when i used those techniques in my project I was not able to get it to work. 回答1: The link you posted is just a general Zend Framework tutorial, and hasn't been updated past ZF 1.5. Anyway, once you get started with Zend, this is a sample of the code you would use to receive an upload. The form doing the posting must have the correct file upload

Zend Framework 2 - Hydrator strategy for Doctrine relationship not working

◇◆丶佛笑我妖孽 提交于 2019-11-27 11:49:47
问题 As mentioned here I'm building a custom hydration strategy to handle my related objects in a select box in a form. My form looks like this: $builder = new AnnotationBuilder($entityManager); $form = $builder->createForm(new MyEntity()); $form->add(new MyFieldSet()); $hydrator = new ClassMethodsHydrator(); $hydrator->addStrategy('my_attribute', new MyHydrationStrategy()); $form->setHydrator($hydrator); $form->get('my_attribute')->setValueOptions( $entityManager->getRepository('SecEntity\Entity

Using ViewScript Decorator on Nested Subforms (Zend Form)

≡放荡痞女 提交于 2019-11-27 08:58:52
I want to use a view script to render my zend form as it seems to be the best way to control the layout/design of the form while still using the Zend_Elements classes. From the view script, I render the element with $this->element->getElement('elementName') . I'm having problems with the names of the elements. This is actually a sub-form inside a sub-form inside a form. When I used the FormElements decorators , the fully qualified name of the elements was form[subForm][subForm][element] , which was good. Wehn I moved to the viewScript decorators, it changed to subForm[subForm][element]. I