last => true
in your rules
Am Dienstag, 20. März 2012 15:19:57 UTC+1 schrieb heohni:
Hi,I have some strange (to me) problems with the validation of my contact form in Cake 2.1This is my model<?php
class Contact extends AppModel {
var $name = 'Contact';
var $useTable = 'contacts';
var $primaryKey = 'con_id';
var $validate = array(
'con_firstname' => array(
'required' => array('rule' => 'notEmpty', 'message' => 'EmptyFirstName')
),
'con_lastname' => array(
'required' => array('rule' => 'notEmpty', 'message' => 'EmptyLastName')
),
'con_email' => array(
'required' => array('rule' => 'notEmpty', 'message' => 'EmptyEmail'),
'email' => array('rule' => array('email', true), 'message' => 'SyntaxEmail')
),
'con_phone' => array(
'required' => array('rule' => 'notEmpty', 'message' => 'EmptyPhone')
),
);
}I do the validation via ajax.My controller is this:$this->Contact->set($this->data['Contact']); if($this->Contact->validates()) {
$message = __('Hurra! ');
$data = $this->data;
$this->set('success', compact('message'));
}else{
$message = __('Oh no');
$Contact = $this->Contact->invalidFields();
$data = compact('Contact');
$this->set('errors', compact('message', 'data'));
}My index view returns the data as json but here comes the problem:if I do this: debug($this->validationErrors['Contact']); at the very first beginning of my index view it returns me this arrayarray
'con_firstname' => array( (int) 0 => 'EmptyFirstName', (int) 1 => 'EmptyFirstName' ), 'con_email' => array( (int) 0 => 'EmptyEmail', (int) 1 => 'EmptyEmail' ) )How the hell I get the error twice here?The returned json look like this then{"errors":{"data":{"Contact":{"con_firstname":[" EmptyFirstName"," EmptyFirstName"],"con_email":[ "EmptyEmail","EmptyEmail"]}}}} Any ideas for me?
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment