views:

70

answers:

2

Using CakePHP 1.3, I post a form which correctly fills in $this->data. According to the docs, it seems like $this->params['form'] should be populated with some information as well, but it's simply an empty array. Is there a particular reason for that?

The form is built using the Form Helper, as follows...

Some relevant code:

$default_form_create_options = array(
    'inputDefaults' => array(
        'label'=>false, 
        'div'=>false
    )
); 

echo $form->create('Preappform', $default_form_create_options);
// --- snip, a bunch of form elements created via $form->input()
echo $form->end(array('label'=>'Send This Form »', 'class'=>'submit-button', 'escape'=>false));

I know that the form data is available in $this->data, so maybe this is just a documentation/curiosity issue. If so... my bad.

+1  A: 

Just for giggles try $this->params['data']. I don't know why but for some reason it shows form data in there for me.

The documentation has conflicting data as you can see here http://book.cakephp.org/view/972/data. I am guessing that if you use the FormHelper it will show up in $this->data and if you don't use the FormHelper it will show up in $this->params['form'].

Notice if you use FormHelper the name of the element will be data['Model']['element_name'] and if you just create the form manually you can name it 'element_name'. By doing the later I believe it throws it into the params['form'] instead of the $this->data.

jostster
If this is the case, then it explains why I'm hating the CakePHP Documentation lately.
anonymous coward
Yup, `$_POST = $this->params['form'];` except when using FormHelper. You should be using the FormHelper in your application to make things easier, so using `$this->data` in the controller is the way to go. However, if people are POSTing to your controller action from an external source (ie. you are providing a web service), you can separate concerns by checking `$this->params['form']` instead.
deizel
A: 

usually you dont need form param

always use $this->data!

mark