I'm trying to use data validation on my model but I don't find where
is my error.
When I leave a form field empty, nothing happens (no message erros).
But when fill all fields, all data is saved to database.
Any skilled guy could help me?
Below are some pieces of my code. If you need any detail, please let
me know.
View code:
<?php
echo $form->create('Property');
echo $form->input('oferta_imovel', array(
'label' => 'Imóvel para:',
'options' => array('1'=>'Locacao', '2'=>'Venda'),
'empty' => '>> Escolha'));
echo $form->input('tipo_imovel', array(
'label' => 'Seu imóvel é:',
'options' => array('1'=>'Casa', '2'=>'Apartamento'),
'empty' => '>> Escolha'));
echo $form->input('endereco_imovel', array(
'label' => 'Endereço:',
'rows' => '3'));
echo $form->input('bairro_imovel', array(
'label' => 'Bairro:'));
echo $form->input('cidade_imovel', array(
'label' => 'Cidade:'));
echo $form->input('valor_imovel', array(
'label' => 'Valor:'));
echo $form->input('estado_imovel', array(
'label' => 'Estado:',
'options' => array('sp'=>'SP', 'rj'=>'RJ'),
'empty' => '>> Escolha:'));
echo $form->end('Enviar');
?>
Model code:
var $validate = array(
'tipo_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'Selecione o tipo do imóvel'
),
'oferta_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'Selecione a oferta de imóvel'
),
'endereco_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'É necessário preencher o endereço'
),
'bairro_imovel' => array(
'rule' => array('minLength', 1),
'required' => true,
'message' => 'É necessário preencher o bairro'
),
'cidade_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'É necessário preencher o cidade'
),
'estado_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'É necessário preencher o estado'
),
'valor_imovel' => array(
'rule' => array('minLength', 1),
'message' => 'Preencha um valor válido'
)
);
Controller method:
function add() {
if (!empty($this->data)) {
if ($this->Property->save($this->data)) {
$this->flash('Seu imovel foi adicionado com sucesso.', '/keizai/
properties');
}
}
}
Thanks very much!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment