Display boolean as radio button in CakePHP form -


does know how display 2 radio buttons in form in cakephp , have them save boolean field in db?

i can boolean value display checkbox (default behaviour) need display 2 radio buttons, when changes don't saved db.

i feel it's simple. here's code:

<h1>edit content</h1>  <?php $thisval = $this->data['lessoncontent']['is_exercise'] ? "1" : "0";  $options = array(     '0' => 'learning material',     '1' => 'exercise' );  echo $this->form->create('lessoncontent', array('action'=>'edit')); echo $this->form->input('name', array('label' => 'name')); echo $this->form->input('description', array('label' => 'description'));  echo $this->form->input('is_exercise', array(     'type'      =>  'radio',     'class'     =>  'radio',     'legend'    =>  false,     'name'      =>  'type',     'options'   =>  $options,     'value'     =>  $thisval ));  echo $this->form->input('id', array('type'=>'hidden')); echo $this->form->input('lesson_id', array('type'=>'hidden')); echo $this->form->end('save content'); echo $this->html->link('cancel', array('controller'=>'lessons', 'action'=>'view', $this->data['lesson']['id'])); ?> 

thanks

you're overriding name of input, therefore value is_excercise sent type.

remove name option;

echo $this->form->input('is_exercise', array(     'type'      =>  'radio',     'class'     =>  'radio',     'legend'    =>  false,     'options'   =>  $options,     'value'     =>  $thisval )); 

note after making change, don't have manually set value of radio-button.

debugging

in situations this, check/debug posted form-data, either via firebug or debugging in cakephp, putting in controller;

debug($this->request); 

even better, install cakephp debugkit plugin plugin shows information (request data, queries, session variables etc.) without having add debug-lines


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -