Thank you both for your answers.

I don't actually want multi-select, I just want the radio option to be
selected when clicking on the corresponding label. At the moment the
ids of all the radio buttons are the same so independent of which
label you click, there would always be the first radio selected.

I also considered the 0 to be the problem, but firstly it doesn't work
without the 0 either. And secondly I need the 0 because I am using
multiple sets of radio buttons in one view. And that's the cake way to
do so.

So I absolutely don't know what's the problem here, I think it should
work with exactly that code.
Do I maybe need to do some special configuration when creating the
form?

On 12 Apr., 15:54, [email protected] wrote:
> > Hey,
>
> > I am having a problem with my radio inputs and the corresponding
> > labels.
> > My code looks like this:
> > <?
> >  echo $form->radio('Model.0.fieldName', array('1' => 'Value1', '2' =>
> > 'Value2', '3' => 'Value3'));
> > ?>
>
> > What I get as a result is
> > <input type="radio" value="1" id="Model0FieldName"><label
> > for="Model0FieldName">Value1</label>
> > <input type="radio" value="2" id="Model0FieldName"><label
> > for="Model0FieldName">Value2</label>
> > <input type="radio" value="3" id="Model0FieldName"><label
> > for="Model0FieldName">Value3</label>
>
> > What I am expecting to get is rather "Model0FieldName1" as "id" and
> > "for" attribute (with the value added) so I could click on each label
> > to select the radio button.
>
> > Does anyone have an idea what I am doing wrong? Since the code is
> > quite simple I don't know where else to look for the error.
>
> you just need to loose the .0.
>
> <?php
>  echo $form->radio('Model.fieldName', array('1' => 'Value1', '2' =>
> 'Value2', '3' => 'Value3'));
> ?>
>
> which produces
>
> <fieldset><legend>FieldName</legend><input type="hidden" value=""
> id="ModelFieldName_" name="data[Model][fieldName]"><input type="radio"
> value="1" id="ModelFieldName1" name="data[Model][fieldName]"><label
> for="ModelFieldName1">Value1</label><input type="radio" value="2"
> id="ModelFieldName2" name="data[Model][fieldName]"><label
> for="ModelFieldName2">Value2</label><input type="radio" value="3"
> id="ModelFieldName3" name="data[Model][fieldName]"><label
> for="ModelFieldName3">Value3</label></fieldset>
>
> which is what you are after.

-- 
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

Reply via email to