I am following this thread to create a form and it is working when No. of form elements are known. Now I have to create form fields based on user choice.
For Example:
<?php class Form_MyForm extends Zend_Form { public function __construct( $options = null ) { parent::__construct( $options ); // Set the method for the display form to POST $this->setMethod('post'); $elements = array(); // Get user input to create elements $fields = $options['columns']; // Create form elements for( $i = 0; $i < count( $fields ); $i++ ) { $element = $this->CreateElement('text', 'field'.$i ); $element->setLabel( $fields[$i]['name'] ); $elements[] = $element; } $this->addElements( $elements ); $this->setElementDecorators( array( 'ViewHelper' ) ); $this->setDecorators( array( array( 'ViewScript', array( 'viewScript' => 'myform-form.phtml' ) ) ) ); } // end construct } // end class ?> I can render each element separately but Now I don't know how to render these elements in myform-form.phtml by looping. I have to loop because No. Fields are not known at the begining..
Thanks
configureForm()and have it accept an argument with the number of fields instead?$columnsvariable? I don't see where it is created.array('FirstName','LastName','BirthDate');Please review the question again. Thanks