Grant, thanks for your time and pointers.
I found that if I set a value explicitly for the radio button, that if
for some reason the form fails validation, the form is rendered again
setting all fields to those explicitly set values. This is problematic
(i.e. if a user chooses Yes for one question, the value is not carried
over correctly after validation to the same form.)
I tried setting the values in the controller, but can't seem to get
that to work properly. I figured I would try using html to code up the
radio buttons instead and that works in the sense that it does not
prepopulate the radio buttons with No. I think I would rather try
that, then have to add a bunch of code into the controller. I guess
this has something to do with the way the radio helper is coded.
Regards
On May 3, 7:27 pm, Grant Cox <[EMAIL PROTECTED]> wrote:
> Provide an explicit start value for the field, that isn't 1 or 0. You
> can do this in your controller ($this->data['SurveyPtsd']['q2'] =
> 'none';), or in the view:
>
> $html->radio('SurveyPtsd/q2', array('1' => 'Yes', '0' =>'No'),
> $inbetween=" ", array('value'=>'none', 'class'
> =>'radio'));
>
> However, if you are only saving 1 or 0 in the database - how can you
> indicate that no choice was made?
>
> On May 4, 8:40 am, halebs <[EMAIL PROTECTED]> wrote:
>
> > I am using the following helper code...
>
> > <?php echo $html->radio('SurveyPtsd/q2', array('1' => 'Yes', '0' =>
> > 'No'), $inbetween=" ", array('class' =>
> > 'radio'));?>
>
> > When the page is first rendered, the radio defaults to No. I guess
> > this has to do with the radio value being empty. Is there a way to
> > have it render with neither value checked?
>
> > I guess I could use values other than the above, like array('y' =>
> > 'Yes', 'n' => 'No'), but then I would have to do a conversion on save,
> > since I capture the values as 0 or 1 in the database table.
>
> > Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---