On Apr 22, 12:50 pm, cricket <[email protected]> wrote:
> I need to display a single radio button at the end of each row of a
> table. Each row pertains to a candidate in an election, and there are
> several groups of rows, one for each office.
>
> I've got single buttons working, and it looks like I got the group
> thing correct. But the submitted data looks wrong.
>
> $office_cnt is incremented after each outer loop (office), and there's
> an inner loop for each candidate.
>
> <?= $form->radio(
>         "ElectionVote.${office_cnt}",
>         array($ballot['id'] => ''),
>         array(
>                 'label' => false,
>                 'legend' => false
>         )
> ) ?>

I just clued in to the fact I was missing the field name.

<?= $form->radio(
        "ElectionVote.${office_cnt}.ballot_id",
        array($ballot['id'] => ''),
        array(
                'label' => false,
                'legend' => false
        )
) ?>

So, now the inputs look like:

<input type="hidden" name="data[ElectionVote][0][ballot_id]"
id="ElectionVote0BallotId_" value="" />
<input type="radio" name="data[ElectionVote][0][ballot_id]"
id="ElectionVote0BallotId2" value="2"  />

But the submitted values were then all empty.

I played around with it a bit more and came up with:

><?= $form->radio(
        "ElectionVote.${office_cnt}.ballot_id",
        array($ballot['id'] => ''),
        array(
                'value' => false,
                'label' => false,
                'legend' => false
        )
) ?>

The 'value' => false suppresses the hidden input (I still don't quite
understand its purpose) while the array($ballot['id'] => '') creates a
single input with value $ballot['id'].

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to