Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
表单操作在验证错误后丢失post ID-CakePHP_Php_Html_Forms_Cakephp_Validation - Fatal编程技术网

表单操作在验证错误后丢失post ID-CakePHP

表单操作在验证错误后丢失post ID-CakePHP,php,html,forms,cakephp,validation,Php,Html,Forms,Cakephp,Validation,如果我没有任何验证错误,我的编辑操作将非常有效 当发现验证错误时,视图会再次呈现错误消息,但表单标记操作中的URL会释放post id e、 g 验证错误之前: <form class="niceInput" id="PostEditForm" method="post" action="/posts/edit/1" accept-charset="utf-8"> 编辑2:添加.ctp视图 if ($this->action == 'edit') { echo $t

如果我没有任何验证错误,我的编辑操作将非常有效

当发现验证错误时,视图会再次呈现错误消息,但表单标记操作中的URL会释放post id

e、 g

验证错误之前:

<form class="niceInput" id="PostEditForm" method="post" action="/posts/edit/1" accept-charset="utf-8">

编辑2:添加.ctp视图

if ($this->action == 'edit') {
    echo $this->Form->create('Post', array('class' => 'niceInput', 'action' => 'edit'));
} else {
    echo $this->Form->create('Post', array('class' => 'niceInput'));
}


echo $this->Form->input('type', array(
                        'label' => 'Type of post',
                        'type' => 'select',
                        'options' => array(
                            'rent' => 'Rental',
                            'roommate' => 'Roommate',
                            'sublet' => 'Sublet'
                        )));
echo $this->Form->input('street_address', array('label' => 'Street address'));
echo $this->Form->input('city');
echo $this->Form->input('province');
echo $this->Form->input('price');
echo $this->Form->input('bedrooms');
echo $this->Form->input('bathrooms');
echo $this->Form->input('utilities', array('label' => 'Utilities Included'));
echo $this->Form->input('washer_dryer');
echo $this->Form->input('dishwasher');
echo $this->Form->input('a_c');
echo $this->Form->input('parking_spots');


echo $this->Form->hidden('image_files');
echo $this->Form->input('description');

if ($this->action == 'edit') {
    $buttonLabel = 'Save changes';
} else {
    $buttonLabel = 'Add house';
}

echo $this->Form->button($buttonLabel, array('id' => 'addButton'));
echo $this->Form->end();

您需要使用表单帮助器并显式设置表单指向的url

<?php echo $form->create('Post', array('url' => $html->url(array('controller'=>'posts', 'action'=>'edit', $this->data['Post']['id'])))); ?>

您需要使用表单帮助器并显式设置表单指向的url

<?php echo $form->create('Post', array('url' => $html->url(array('controller'=>'posts', 'action'=>'edit', $this->data['Post']['id'])))); ?>


你能发布你的<代码>编辑方法代码吗?你能发布你的<代码>编辑方法代码吗。。但是cake不应该自动完成吗?这是1.2语法;如果您使用的是1.3,它应该是
$this->Form->Create('Model')
,但在其他方面是正确的。是的,Cake应该自动完成这项工作(只是模型名),您的编辑视图中有什么?我呈现add视图,它有一个条件$this->Form->create('Post')。如果操作为编辑,则它包含“action”=>“edit”参数。否则,它将只回显$this->Form->create('Post'),我这样做了,它就工作了。。但是cake不应该自动完成吗?这是1.2语法;如果您使用的是1.3,它应该是
$this->Form->Create('Model')
,但在其他方面是正确的。是的,Cake应该自动完成这项工作(只是模型名),您的编辑视图中有什么?我呈现add视图,它有一个条件$this->Form->create('Post')。如果操作为编辑,则它包含“action”=>“edit”参数。否则,它将只回显$this->Form->create('Post')
<?php echo $form->create('Post', array('url' => $html->url(array('controller'=>'posts', 'action'=>'edit', $this->data['Post']['id'])))); ?>