label currently sets the male radio button as selected. Also, I'm
guessing my issue is probably in the options array...
On Oct 31, 4:29 pm, dave <davespa...@gmail.com> wrote:
> Got quite lengthy when writing it, but essentially my question below
> is how to make radio button labels clickable. Pls read on...
>
> Quite new to Cakephp, and very pleased with results so far, but
> perplexed by radio buttons. More accurately, adding labels with the
> correct 'for' attribute to make them clickable alongside the correct
> radio button (ie where the radio button 'id' and the label 'for' are
> the same for each individual radio button).
>
> The form looks perfect, and indeed works perfectly if the user clicks
> the actual radio button - but I feel the label should be clickable (am
> I getting too anal here?)
>
> What I want to achieve:
>
> <input type="radio" value="1" class="list required" id="1"
> name="data[Member][gender]">
> <label for="1">Male</label>
> <input type="radio" value="2" class="list required" id="2"
> name="data[Member][gender]">
> <label for="2">Female</label>
>
> What I'm getting:
>
> <input type="radio" value="1" class="list required" id="MemberGender"
> name="data[Member][gender]">
> <label for="MemberGender">Male</label>
> <input type="radio" value="2" class="list required" id="MemberGender"
> name="data[Member][gender]">
> <label for="MemberGender">Female</label>
>
> (for info the controller is members_controller.php, using LoadModel to
> incorporate the Question model)
>
> So my question is how do I get the correct values in 'id' on the input
> and 'for' on the label. I know it should be simple, and have tried
> many many variations of what's going into my options array
> etc...........any help would be much appreciated.
>
> Here's my code as it stands:
>
> $options = array();
> $c = 0;
> while ($c < count($question['Reply'])) {
> $options[$question['Reply'][$c]['id']] = $question['Reply'][$c]
> ['value'];
> $c++;
>
> }
>
> echo $this->Form->input($question['Question']['name'], array(
> 'type' => 'radio',
> 'class' => 'list required',
> 'options' => $options
> ));
>
> All taken from two tables, questions and replies - related via
> question.id and reply.question_id
>
> Questions have many replies, so relationship in the Question model is:
>
> var $hasMany = array(
> 'Reply' => array(
> 'className' => 'Reply',
> 'foreignKey' => 'question_id',
> 'dependent'=> true
> )
> );
>
> The output from doing a find all of a certain question_id (in this
> case gender) is:
> (
> [0] => Array
> (
> [Question] => Array
> (
> [id] => 15
> [group_id] => 1
> [name] => gender
> [text] => Gender?
> [abbr_text] => Gender
> )
>
> [Reply] => Array
> (
> [0] => Array
> (
> [id] => 1
> [question_id] => 15
> [value] => Male
> )
>
> [1] => Array
> (
> [id] => 2
> [question_id] => 15
> [value] => Female
> )
>
> )
>
> )
>
> Sorry for length, hope someone can help. Thanks...D
--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment