Hi Karol,

the problem seems trivial at first glance, since it could be solved by a simple if($a != $b) echo "Error"; - but this would break the elegance of defining all your validation logic in one place and have only one single mechanism to determine whether or not your form has validated, and to display error messages in a standardized way for all form fields.

This may not be an issue if you write all your forms by hand, but as soon as you try automating form generation based on dynamic rule sets, it can become one rather quickly - you suddenly can't treat one field differently than the others anymore.

Concerns regarding elegance and automation aside, while researching this seemingly tiny problem, I have come about a bigger issue: Validation using Zend_Filter_Input can not be made across multiple fields at all.

Why would this be neccessary? Imagine a form where validation rules can depend on other fields' input values. For example, field B is a required field *only* if the value entered in field A is not empty (or an integer greater than 42, or... you name it) - otherwise, field B is optional. Right now, unless I have missed something, this is not possible.

CU
 Markus

Karol Grecki schrieb:
Markus

I think this problem is so trivial that it doesn't require a dedicated
validator.
You usually need it once during signup and it's solved by simple ==
operator.

Regards
Karol


Markus Wolff wrote:
Hey Jason,

that's where I was looking and couldn't find any. Sure, I can write my own validator, I just couldn't believe I was the first one finding the obvious gap in the existing validators.

What I need is a validator that compares one field's value to another. Something along the lines of:

$f = array();
$v = 'password' => array(
         array('SameAsField', 'password2')
       );
$input = new Zend_Filter_Input($f, $v, $_POST);
if ($input->hasInvalid()) {
     echo "Uh-oh, the password fields do not contain the same value!";
}

Now, is the field "password" does not have the same value as the field "password2", then an error message is shown.

Am I the only one finding this useful? If not, how does one go about adding validators? Is a proposal needed or should I just send the code to the package maintainer?

CU
  Markus

Jason Qi schrieb:
Hi Markus,

Do you think the Standard Validation Classes is useful
for you?
http://framework.zend.com/manual/en/zend.validate.set.html

Or you might write Validators yourself to fit your
needs. see here:

http://framework.zend.com/manual/en/zend.validate.writing_validators.html

Regards,

Jason.

--- Markus Wolff <[EMAIL PROTECTED]> wrote:

Hi there,

quite often one has to make a form where a user can
create a user account. It's customary to add two password fields, and add a validation rule so that when the entries in both fields do not match, an error message is presented to the user.

I was searching for such a validation rule for use
with Zend_Filter_Input, but couldn't find any. Am I missing something? Or would you guys do it entirely differently?

CU
  Markus




Reply via email to