Q1: The form is doing exactly what you want it to as the $i is inside single
speech marks. Try $this->Form('Member.'.$i.'.name', ... then see what happens
with validation.
Jeremy Burns
Class Outfit
http://www.classoutfit.com
On 27 Jun 2011, at 20:38, Sanfly wrote:
> My question is in two parts
>
> Im making a form that has a certain part of it built with a 'for'
> loop. This form is for a booking: the first couple of fields are for
> the main contact details for the booking, the looped section is to get
> the details for each person included in the booking, up to a maximum
> of 10 people.
>
> Please note: at this point the information is not being stored in a
> database, just being emailed.
>
> Below is my form as I have it now. I have removed some fields to
> simplify it for this purpose, but once the form is submitted, some
> validation is done.
>
> Question 1:
>
> Is there any way that I can use cakePHP to build the looped form
> fields?
>
> <?=$this->Form->text('Member.$i.name', array("size" => "40", "label"
> => false));?> does not work within the for loop, the fields end up
> with: name="[Member][$i][name]" rather than name="[Member][1][name]"
> etc...
>
> Question 2
>
> I want to do the validation and if there are issues, have the form
> repopulated with the data (if all okay, will redirect to another
> page). My non-looped fields are repopulated with the data, but not
> the looped fields. What is required to get this to happen?
>
> Hope this all makes sense...
>
>
> <?=$this->Form->create('booking', array('url' => '/bookings/
> bookingform', 'onSubmit' => 'return checkRequiredFields()'));?>
> <table width="100%">
> <tr>
> <td align="right"><b>Name: </b></td>
> <td><?=$this->Form->text('Booking.name', array("size" => "40",
> "label" => false, "onBlur" => "copyName()"));?> <b style="color:
> #FF0000">*</b> </td>
> </tr>
> <tr>
> <td align="right"><b>Email: </b></td>
> <td><?=$this->Form->text('Booking.email', array("size" => "40",
> "label" => false));?> <b style="color: #FF0000">*</b> </td>
> </tr>
> </table>
> <br>
> <table cellpadding="0">
> <tbody>
> <tr>
> <td width="190"><b>Full Name</b></td>
> <td width="40"><b>Age<br><span style="font-size:
> smaller">(if under
> 25)</span></b></td>
> </tr>
> <? for ($i = 1; $i <= 10; $i++){ ?>
> <tr>
> <td><input type="text" size="22"
> name="data[Member][<?=$i?>][name]"
> id="Member<?=$i?>Name"></td>
> <td><input type="text" size="3"
> name="data[Member][<?=$i?>][age]"
> id="Member<?=$i?>Age"></td>
>
> </tr>
>
> <? } ?>
> <tr>
> <td colspan="5">
> <?=$this->Form->button('CANCEL', array('style'
> => 'display:
> inline', 'onclick' => 'history.back()')); ?>
> <?=$this->Form->button('FINISH BOOKING',
> array('id' =>
> 'finishSubmit', 'type'=>'submit', 'style' => 'display: inline', 'name'
> => 'submit', 'value' => 'finshApplication', 'onclick' => "
> if(confirm('Are you sure?')){return true;}return false; "));?>
> </td>
> </tr>
> </table>
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php