开发者

I'm not specifying the form action but it (automatically) gives different values in some cases

开发者 https://www.devze.com 2023-02-24 02:47 出处:网络
I\'m creating my form using the Form helper, so the action of the form is specified automatically....

I'm creating my form using the Form helper, so the action of the form is specified automatically....

this form is used for editing a post..

so, the URL has the structure: mywebsite.com/posts/edit/id and the form's action should be automatically generated as posts/edit/id

but the problem is, in some cases, I open the HTML code and I find that the form's action is only posts/edit without the id which causes the update to fail...

I spent a lot of time to figure out what situation brings this wrong action:

  • i'm genera开发者_运维技巧ting fields dynamically (using javascript & ajax) depending on the post's category..
  • when the value of one of the dynamically generated fields is invalid, the generated action becomes posts/edit !!

I really need help, cuz I don't know why this is happening !!!

and I don't wanna waste more time digging into the core of cakephp...

so, if any of cakephp experts has an idea about this, plz help me !!

thank you in advance !


Use the url parameter, which allows you to explicitly define a url for the form:

echo $form->create('Post', array('url' => $html->url(array('action'=>'edit', $id))));


It sounds like $id probably isn't getting set, because it should be getting passed along if it is. You need to make sure it's set to edit the record in question. Make sure your javascript is including the hidden field with the record's id in it.

Normally done like this, with the form helper: echo $this->Form->input('id');

Also, if one of the fields is invalid, the form shouldn't actually be submitting properly, if you are using cake's validation, so this is to be expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消