【问题标题】:cakephp form not submitted correctly after JS added a new fieldJS添加新字段后cakephp表单未正确提交
【发布时间】:2023-03-30 07:48:01
【问题描述】:

观点

<?php echo $this->Form->create('Practice');
echo $this->Form->input('title',array('value'=>'test value'));
echo $this->Js->submit('Ajax Submit', array(
'update' => '#left',
 'url'=>'/practices/content',
 'async' => true,
 'method' => 'post',
 'dataExpression'=>true,
 'data'=> $this->Js->serializeForm(array(
     'isForm' => true,
     'inline' => true 

  ))
    ));
?> <?php echo $this->Form->end(); ?>

表单在 Ajax 提交之前工作正常。 ajax 提交实际上返回相同模型的新表单字段。下面是首先为 ajax 发送表单的视图

echo $this->Form->input('Practice.options',array('value'=>'regex value'));

新字段值未与表单一起提交

【问题讨论】:

  • 表单结束标签存在,但解决方案仍然没有变化

标签: javascript forms cakephp-2.1


【解决方案1】:

我犯了两个错误,第一个是新的 ajax 返回的字段不在表单标签内第二个我需要绕过 cakephp 安全检查

function beforeFilter() {
        parent::beforeFilter();
        $this->Security->blackHoleCallback = 'blackhole';
        $this->Security->csrfCheck = false;
        $this->Security->validatePost = false;
        $this->set('contentLayout', 'admin_dashboard');
    }

【讨论】:

    【解决方案2】:

    确保您的放在表格末尾

    <?php echo $this->Form->end(); ?>
    

    然后您解锁 SecurityComponent 的当前操作

    【讨论】:

    • 我已经反查过是否有结束标签
    猜你喜欢
    • 2013-08-24
    • 2020-08-27
    • 2021-04-16
    • 2020-11-12
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多