In CakePHP, why would $this->params['form'] be empty if I've just posted a form?

↘锁芯ラ 提交于 2020-01-16 06:40:28

问题


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:


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.




回答2:


I too faced the same while working with CakePHP 1.3. Later I solved the issue by using the $this->params['data']. But I have some questions, I'm a newbie to cakephp and using the manual as my reference, it seems that the manual is not at all updated, while searching about this issue, I found out that it was working well in earlier versions and after 1.2, it is not at all there in Cakephp. Is there any CakePHP experts to clarify this stuff ?




回答3:


Not necessarily related to Cake, but the answer to the problem when I had it: if you're including a file upload in your POST, double-check that the file you're uploading isn't larger than the limit specified in your php.ini file.



来源:https://stackoverflow.com/questions/3771169/in-cakephp-why-would-this-paramsform-be-empty-if-ive-just-posted-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!