I hope some of you experts out there could help me out on this. I'm kind of
new to Zend Form SubForm and have not been able to comprehend with the
concept of this component. Tried googling and hasn't stumbled upon any
helpful websites to improve my understanding over it.
Here's what I'm trying to do. Imagine in my website it has a shopping cart
which contains all the items that a user have picked from a catalogue. Now
at the checkout page, the user is required not only to enter his/her details
but also to enter the quantity and specify the colour of each item he/she
has in her shopping cart. Hence programatically, I'm suppose to have a loop
to go through the array of cart items and create instances of the sub form
for each cart item.
Below is my Zend_Form code:
class My_Checkout extends Zend_Form {
public function init() {
$this->addElement('text','firstname',array(
'required'=>true,
'label'=>'First Name:'
));
$this->addElement('text','lastname',array(
'required'=>true,
'label'=>'Last Name:'
));
$table = new MyCart();
$rowset = $table->fetchAll();
foreach ($rowset as $item) {
$subform = new Zend_Form_SubForm();
$subform->addElement('text','itemid',array(
'value'=>$item->name,
'required'=>true,
'disabled'=>true
));
$subform->addElement('text','qty',array(
'value'=>1,
'required'=>true
));
$subform->addElement('text','color',array(
'value'=> 'black', // by default color
'required'=>true
));
$this->addSubForm($subform,"" . $item->id);
} // foreach
} // init function
The following would be the desired output which I have not been able to
produce successfully:
<form>
<input type='text' name='firstname' value='' />
<input type='text' name='lastname' value='' />
<input type='text' name='itemid[]' value='' />
<input type='text' name='qty[]' value='1' />
<input type='text' name='color[]' value='' />
</form>
Could anyone help out on this?
--
View this message in context:
http://www.nabble.com/Zend-Form-SubForms-difficulties-tp24564572p24564572.html
Sent from the Zend Framework mailing list archive at Nabble.com.