Dynamic form fields and multiple inputs

Hi there,

First of all, first post =D Thanks for the yii framework, works great. And, sorry for my English, as I am a French Canadian.

I’m currently building a web application that will allow people to buy and sell their stuff. In order for them to sell, they have to fill a form which is 4 fields

  • The name

  • The description

  • The category

  • A checkbox, true meaning they’re selling. Otherwise, they buy

Since people may have more than 1 item to sell at once, I placed some jQuery in it in order to duplicate these fields. I am using latest jQuery release with a plugin that is called "relCopy". It can be found there: http://www.9lessons.info/2010/04/jquery-duplicate-field-form-submit-with.html

But when I make a var_dump of my post variable, I receive only the last item that has been entered…I double checked what I was usually doing in PHP (without yii) and everything seems fine:

on my _form.php, my items go as follow (only an example)

 <?php echo $form->textField($model,'ITE_Name[]',array('size'=>80,'maxlength'=>45)); ?>

However, I’ve noticed that it’s written on the source code

 <input size="80" maxlength="45" name="Item[ITE_Name]" id="Item_ITE_Name" type="text" value="" />

Why are the brackets missing at the end ? I think this is why, when I receive the form there’s only the last insert.

So I’m wondering. Shall I use standard html forms for this one, or is there an implemented method that works great in Yii ? I searched on google but the keywords are too common and generate alot of trash results.

Thanks for your replies!

You have to collect tabular input, there is a page in the definitive guide to Yii.

You have to generate the feld like that:

<?php echo $form->textField($model,'[$i]ITE_Name',array('size'=>80,'maxlength'=>45)); ?>

Where $i is an index (count from 1 to the number of your elements in page). Like that the input field will be:

 <input size="80" maxlength="45" name="Item[0][ITE_Name]" id="Item_0_ITE_Name" type="text" value="" />

And you will have receive:








Read the manual about it.

Thank you. I didn’t know it is named “tabular input”.

With some tweaks, it definitely works!

Thanks again

Hi, could you post all your code please.

I want to create an invoice and add products one by one during filling the form.


There is an extension for help in mananging tabular input.

Can you please post your code…

I also want ot use it in my project so please help me…