tags:

views:

97

answers:

1

Hi all,

I was manually creating a simple form with one input text box field like this:

<form action="/user/add" method="post">
<input type="text" name="data[user_id]" value="1">

But when I call $this->model->save($this->data) in the Controller,
nothing was saved to the Table.

Only when I used this and the data in the field was written to the database successfully:

$form->create(null, array('url' => '/user/add'));
echo $form->input('user_id', array('label' => 'User ID', 'value' => '1'));
+2  A: 

If you want to create the form manually,the name of the input part should be

<input type="sometype" name="data['modelname']['fieldname']" value="somevalue">

And in your code that should be

<form action="/user/add" method="post">    
<input type="text" name="data['User'][user_id]" value="1"> 

See automagic form elements in the cookbook.

SpawnCxy
+1, You should look at the source of the working code, and see for yourself what the form elements are named. And you do need to create a form anyhow!
sibidiba
@ sibidiba,Oh no,u've forgotten the vote, lol
SpawnCxy
Correct answer, I voted an up :)
Ashok
Thanks all for the helpspecial thanks to SpawnCxy