简体   繁体   中英

Data not inserted when form is submitted in CakePHP

My data is not submitting when I click on submit button on add page form. Below is my code.Any help would be greatly appreciated.. This is my controller function:

public function add()
{
    $complejo = $this->Complejos->newEntity();
    if ($this->request->is('complejo')) {
        $complejo = $this->Complejos->patchEntity($complejo, $this->request->data);
        if ($this->Complejos->save($complejo)) {
            $this->Flash->success(__('El complejo se ha guardado con éxito.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('El complejo no se ha guardado. Por favor intente de nuevo.'));
        }
    }

    $ciudades = $this->Complejos->Ciudades->find('list', ['limit' => 200]);
    $this->set(compact('complejo', 'ciudades'));
    $this->set('_serialize', ['complejo']);
}

And this is my add.ctp

    <nav class="large-3 medium-4 columns" id="actions-sidebar">
<ul class="side-nav">
    <li class="heading"><?= __('Actions') ?></li>
    <li><?= $this->Html->link(__('List Complejos'), ['action' => 'index']) ?></li>
</ul>
</nav>
<div class="posts form large-9 medium-8 columns content">
<?= $this->Form->create($complejo) ?>
<fieldset>
    <legend><?= __('Agregar Complejo') ?></legend>
    <?php
        echo $this->Form->input('nombre');
        echo $this->Form->input('descripcion');
        echo $this->Form->input('ciudadFK', ['options' => $ciudades]);
        echo $this->Form->input('nombreUsuario');
        echo $this->Form->input('contrasenia');
        echo $this->Form->input('direccion');
        echo $this->Form->input('latitud');
        echo $this->Form->input('longitud');
        echo $this->Form->input('telefono');
        echo $this->Form->input('telefono2');
        echo $this->Form->input('vestuario', array('options' => array('Si'=>'Si', 'No'=>'No')));
        echo $this->Form->input('asador', array('options' => array('Si'=>'Si', 'No'=>'No')));
        echo $this->Form->input('estacionamiento', array('options' => array('Si'=>'Si', 'No'=>'No')));
        echo $this->Form->input('requiereSenia', array('options' => array('1'=>'Si', '0'=>'No')));
        echo $this->Form->input('horaDisponible');
        echo $this->Form->input('tiempoReserva');

    ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>

Nothing happens when I click on submit. Thanks

AS @AIPDTECH said:

I have to change in my controller for this:

$this->request->is('post')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM