Be careful using the alphaNumeric and money validation rules as they require
UTF-8 support for PCRE.  On a stock Centos 5 install (or Redhat ES5) I have
PCRE 6.6 06-Feb-2006  compiled in.    The following script fails (the
alphaNumeric test from CakePHP 1.2 validation.php):

<?php
$match=preg_match("/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu", "VISA");
if ($match) {
  echo "good match!\n";
} else {
  echo "bad match!\n";
}
?>

If you don't need UTF-8 alphaNumeric support I recommend a simpler match
expression:

  /^[A-Z0-9]+$/

--Dave


Oribium wrote:
> 
> 
> I am taking a look at cake 1.2, and I run into problems with the
> validation
> of form data. I took advantage of the console application to bake some
> views, a model, and a controller based on an existing MySQL-database.
> I
> don't yet have a deep understanding of cake, and would happily welcome
> hints and pointers which direction I should go.
> 
> I am trying to post data from a form to a database. However, whatever
> data
> I post, I get redirected back to the form, where a label "This field
> cannot
> be left blank" is attached to all fields. For instance if I fill the
> alphanumeric field "last_name" with "Jones" (without qoutes), I will
> get
> the error message: "This field cannot be left blank". Futhermore,
> $this->validationErrors contains all fields and the same error
> message. I
> have verified that the correct data from the form are assigned to the
> controller object's data array with Configure::write('debug', 3);
> 
> The view is just a simple form like:
> 
> echo $form->create('Lead');
> echo $form->input('last_name');
> echo $form->input('modified_user_id');
> ... quite a few more fields here ...
> echo $form->end('Submit');
> 
> There are also a few form fields added with pure html code. These
> fields
> are not supposed to be posted to the database, neither be validated
> with
> the standard cake validation feature.
> 
> In the model, there is nothing but "name" and the validation array.
> 
> The model's validation array looks like:
> 
> var $validate = array(
> 'last_name' => array('alphanumeric'),
> 'modified_user_id' => array('alphanumeric'),
> --- quite a few more fields here ---
> )
> 
> The controller's add function:
> 
> function add() {
> if (!empty($this->data)) {
> if ($this->RequestHandler->isPost()) {
> $this->Lead->create();
> $this->Lead->set($this->data);
> if ($this->Lead->save($this->data)) {
> $this->Session->setFlash(__('The Lead has been saved', true));
> $this->redirect(array('action'=>'index'));
> } else {
> $this->Session->setFlash(__('The Lead could not be saved. Please, try
> again.', true));
> }
> }
> }
> }
> 
> I also tried the following code in the controller: if
> ($this->Lead->validates()) with the same result.
> 
> PHP version: 5.1.6
> OS: Linux
> 
> CakePHP version:
> $Id: VERSION.txt 7692 2008-10-02 05:06:48Z nate $
> 
> libs/model/model.php version:
> $Id: model.php 7690 2008-10-02 04:56:53Z nate $
> 
> > 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Validation-problem-tp21051012p21315909.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to