1

After a lot of searches i found the trouble but i have no idea how to fix it.

When i set the form to enctype="multipart/form-data" the CakePHP2 send an empty $_POST, the same case print $this->request->data. If i remove the add() method works as well.

It occurred after migrating from Windows to Debian, but i've checked permissions and edited php.ini (POST_MAX_SIZE and UPLOAD) and seems perfect.

add() code

        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);

Front-end

<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>

debug output

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

note: i've removed the file upload block, i figured out is useless

7
  • 1
    First question Is your form POSTing or GETting?
    – RiggsFolly
    Jul 26, 2019 at 13:54
  • I'm sending as POST. Jul 26, 2019 at 13:55
  • 1
    debug($this->getRequest()->getData()); exit; and post output in your question
    – Salines
    Jul 26, 2019 at 13:57
  • 1
    ok, than debug($this->request->data); exit;
    – Salines
    Jul 26, 2019 at 14:01
  • 1
    What is your front-end code?
    – Bobot
    Jul 26, 2019 at 14:19

1 Answer 1

0

After more time spent i found the trouble.

Someone has changed my internet security (by IE), after reseting the configuration everything works fine.

If someone knows why it affects when using enctype="multipart/form-data" i give you best answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.