【问题标题】:CakePHP does not send POSTCakePHP 不发送 POST
【发布时间】:2019-07-26 13:45:11
【问题描述】:

经过大量搜索,我发现了问题,但我不知道如何解决它。

当我将表单设置为enctype="multipart/form-data" 时,CakePHP2 发送一个空的$_POST,同样的情况下打印$this->request->data。如果我删除 add() 方法也可以。

它发生在从 Windows 迁移到 Debian 之后,但我检查了权限并编辑了 php.ini(POST_MAX_SIZE 和 UPLOAD),看起来很完美。

add()代码

        if ($this->request->is('post')) {
            $this->Request->create();

            if ($this->Request->save($this->request->data)) {
                $this->Flash->success(__('A solicitação foi enviada com sucesso'));

                return $this->redirect(array('action' => 'index'));
            } else {
                $this->Flash->error(__('The request could not be saved. Please, try again.'));  

                //print_r($this->Request->validationErrors);

前端

<div class="requests form">
<?php echo $this->Form->create('Request', array('type' => 'file')); ?>
    <fieldset>
        <legend><?php echo __('Enviar solicitação'); ?></legend>
    <?php
        echo $this->Form->input('user_id', array('hidden', 'label' => false, 'value' => AuthComponent::user('id')));
        echo $this->Form->input('hash', array('hidden', 'label' => false, 'value' => md5(uniqid(rand(), true))));
        echo $this->Form->input('email', array('label' => 'E-mail'));
        echo $this->Form->input('fullname', array('label' => 'Nome completo'));
        echo $this->Form->input('city_id', array('label' => 'Cidade'));
        //echo $this->Form->input('contract', array('label' => 'Contrato', 'type' => 'file', 'accept' => 'application/pdf'));
        echo $this->Form->file('contract');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Solicitar')); ?>
</div>

调试输出

/app/Controller/RequestsController.php (line 77)
array()

注意:我已经删除了文件上传块,我发现没用

【问题讨论】:

  • 第一个问题是您的表单是 POSTing 还是 GETting?
  • 我作为 POST 发送。
  • 调试($this->getRequest()->getData());出口;并在您的问题中发布输出
  • ok,比 debug($this->request->data);退出;
  • 你的前端代码是什么?

标签: php cakephp cakephp-2.0


【解决方案1】:

花了更多时间后,我发现了问题。

有人更改了我的互联网安全(通过 IE),重置配置后一切正常。

如果有人知道为什么在使用enctype="multipart/form-data" 时会受到影响,我会给你最好的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 2018-08-07
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多