Wow, not really sure what to say. The example you provided is pretty much what I have now. I still have not gotten an answer. Can cake dynamically create the post array key, again referencing this example:? <input type="text" name="name[]"> Maybe none of you have seen this because it is not possible in cake. But I would like a definitive answer from somebody.
Let me explain what my form is doing. I assume that the dilemma is not understood. Basically there is a variable number of classes. The user opts to register for the class using a checkbox and then indicates the number of seats they wish to purchase. Now what I would love to know is how in cake land the association between selected classes and number of seats is made for the purpose of forming a query. Remember the array will have 20 key/values if there are 20 classes even if only 3 are selected. Then for the three how do you know the proper key/value in the text (no seats) array? I think in cake that is called a controller. I would like someone to write a routine to accomplish this without reqiring a bunch of string manipulation. Has anyone here developed anything not using cake? On Feb 19, 10:26 pm, cricket <[email protected]> wrote: > On Sat, Feb 19, 2011 at 6:54 PM, Thomas <[email protected]> wrote: > > Basically if I remove the $i from the input in cake it renders all the > > inputs the same name, or key if you will, I do not need to get rid of > > the loop. I do not know the length of the loop as it is variable. I > > will attach again what I have with cake and a snippet from a regular > > php project that show what I need to do. > > > This is cake-> > > echo $form->checkbox('OnsiteTrainingClass.select_class'. > > $i,array('id'=>'select'.$i,'label'=>'','value'=> > > $value['OnsiteTrainingClass']['id'])); > > echo $form->text('OnsiteTrainingClass.seats'. > > $classid,array('id'=>'select'. > > $i,'label'=>'','value'=>'1','size'=>'2')); > > It looks to me like the loop is something like this: > > foreach ($values as $i => $value) > { > echo $form->checkbox( > 'OnsiteTrainingClass.select_class'.$i, > array( > 'id'=>'select'.$i, > 'label'=>'', > 'value'=> $value['OnsiteTrainingClass']['id'] > ) > ); > > } > > Although, why the label is empty is another thing. > > If the association is HABTM, you could probably get what you're after by > doing: > > $this->set( > 'classes', > $this->YourModel->OnsiteTrainingClass->find('list') > ); > > echo $form->select( > 'OnsiteTrainingClass.OnsiteTrainingClass', > $classes, > null, > array('multiple' => 'checkbox') > ); > > No, I don't know why the model name must be repeated. > > Another situation is where you've got an unknown number of hasMany > items. For a Poll plugin I wrote, the form starts out with 4 empty > PollOption elements, and some JS allows for adding more or removing > some elemnts. This is the naming format used: > > <?= $this->Form->input('PollOption.0.title', array('label' => false, > 'class' => 'PollOption')) ?> > <?= $this->Form->input('PollOption.1.title', array('label' => false, > 'class' => 'PollOption')) ?> > <?= $this->Form->input('PollOption.2.title', array('label' => false, > 'class' => 'PollOption')) ?> > <?= $this->Form->input('PollOption.3.title', array('label' => false, > 'class' => 'PollOption')) ?> -- 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
