tags:

views:

219

answers:

2

I have a add.ctp... In the model I want to add I have a relation belongsTo, so when I generate that add view he creates a dropdownlist input.

But I want to use radiobuttons instead... I already have the code of the radio button and inside the view I can get wich one is selected.

My problem is, how I pass that value to the controler inside the $this->data array? Or should I just use $_POST inside the controler and do a savefield after the record is created?

A: 

The key is the correct naming of the radiobuttons. If for example you have a blog-post form that belongsTo a User, than the radiobutton should look like this:

<input type="radio" name="data[Post][user_id]" value="1" /> Name 1

debug($this->data) should then have the correct entry

harpax
Oops that was pretty simple lol :p Thanks
NoOne
A: 

keep it consistent... use cakephp's helpers

echo $form->radio('user_id');

or see if this works

echo $form->input('user_id',array('type' => 'radio'));

this will generate you the required form elements. the element name will be exactly like in the answer by harpax but it is good practice to use cakephp's helper functions rather than writing your own html.

Yash
I need to have unique Id and value for each radio button, how do I set that using cake helper?
NoOne
does it not generate a unique id for each radio button? i'm sure the value will be different based on the list of users you pass to the view from the controller.
Yash