Form via post and pass in beforeSave

Asked

Viewed 41 times

0

I’m not able to send the data via post, is via put.

You’re not going through callback beforeSave and when I debug the request in the controller, you’re put. Maybe that’s why you don’t pass callback beforeSave.

Follow part of the codes:

http://www.hastebin.com/luyumawiye.vhdl

//formulario
<html>
<body>
<?php
   echo $this->element('menuReceitas');
?>

<?php
   echo $this->Form->create('Receita, array('type'=>'post'));
   echo $this->Form->hidden('id_receita');
   echo $this->Form->input('receita', array('label'=>'Receita','readonly'=>'readonly'));
   echo $this->Form->input('valor_receita', array('label'=>'valor'));
   echo $this->Form->input('data_receita', array('label'=>'Data', 'type'=>'text'));
   echo $this->Form->input('detalhamento', array('label'=>'Detalhamento', 'readonly'=>'readonly'));
   echo $this->Form->end("Alterar");
?>
</body>
</html>

//model

public function beforeSave() {
   $this->data['Receita']['valor_receita'] = $this->valor($this->data['Receita']['valor_receita']);
   $this->data['Receita']['data_receita'] = $this->data($this->data['Receita']['data_receita']);

   return true;
}

//controller

public function alterar($idReceita) {
   if ($this->request->is('get')) {
      $this->Receita->id = $idReceita;
      $this->request->data = $this->Receita->read();
   } else if ($this->request->is('post')) {
      $this->Receita->id = $idReceita;

      if ($this->Receita->save($this->Receita)) {
         echo $this->Session->setFlash("Receita alterada");
      } else {
         echo $this->Session->setFlash("Receita não alterada");
      }
   }
}

1 answer

0


Beneath the scenes, Cakephp sets the form request to PUT.

So in the instruction Else if ... change the is('post') for is('put').

Browser other questions tagged

You are not signed in. Login or sign up in order to post.