Tuesday, March 27, 2012

Re: Is it possible to implement a "no answer" null value on a boolean field?

You shouldn't be using booleans as keys, just use strings.

$options = array('1' => 'yes', '0' => 'no');
echo $this->Form->input('music', array('options' => $options, 'empty' => 'no answer'));


On Tuesday, March 27, 2012 2:16:28 PM UTC-7, Daniel wrote:
Is it possible to implement a "no answer" null value on a boolean
field?  For example this is what I have in the view but it does not
work:
$options = array(true => 'yes', false => 'no', null => 'no answer');
echo $this->Form->input('music', array('options' => $options, 'empty'
=> null));

Answering 'no' saves ok to the database, but it shows '(no answer)'
when editing the record.  And giving 'no answer' does not save a null
to the database.  What's the correct way to do this?

Thanks.

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