I have two rules in two fields.
In the data_expenditure field, I want to get the form d/m/a
and pass a-m-d
. It turns out that when saved in the database, it stays as 0000-00-00
. I do not know how to debug in the model to see how it is transforming and in the controller, when debugging $this->request->data
) does not get validated.
The valor_despesa
field is ok. You are changing the "," to ".". The problem is only in the formatting of data_despesa
.
What's wrong?
Follow the model code:
<?php
class Despesa extends AppModel {
public $name='despesa';
public $useTable='despesas';
public $primaryKey='id_despesa';
public $validate=array(
'data_despesa'=>array(
'data'=>array(
'rule'=>array('data'))),
'valor_despesa'=>array(
'preco'=>array(
'rule'=>array('preco'))));
public function data($check) {
$dataDespesa=explode("/", $check['data_despesa']);
$dataDaDespesa="";
$dataDaDespesa=$dataDespesa[2]."-".$dataDespesa[1]."-".$dataDespesa[0];
return true;
}
public function preco($check) {
$valorDespesa=str_replace(",", ".", $check['valor_despesa']);
return true;
}
}
?>