PHP Classes

Compare two values

Recommend this page to a friend!

      Another Form generator  >  All threads  >  Compare two values  >  (Un) Subscribe thread alerts  
Subject:Compare two values
Summary:Howto Compare two values in a validator
Messages:5
Author:Bertol, Alexander
Date:2011-07-05 09:26:10
Update:2011-07-14 12:29:24
 

 


  1. Compare two values   Reply   Report abuse  
Picture of Bertol, Alexander Bertol, Alexander - 2011-07-05 09:26:10
Hi mate!

@ 1. it's a greate class! But I don't konw hotwo compare 2 values (eg password and retype_password as validator) how can I do this as validation?

  2. Re: Compare two values   Reply   Report abuse  
Picture of Gergely Aradszki Gergely Aradszki - 2011-07-05 09:53:05 - In reply to message 1 from Bertol, Alexander
Hi!

Every validator function receives the contents of all the fields as the 3rd parameter of the validator function, so a sample function could be:

public function password($pass1, $aux, $data){
$pass2 = $data['password_2'];
if ($pass1==""){
return 'no password given';
}
if ($pass1 != $pass2){
return 'password do not match';
}
return false;
}

  3. Re: Compare two values   Reply   Report abuse  
Picture of Bertol, Alexander Bertol, Alexander - 2011-07-05 10:46:29 - In reply to message 2 from Gergely Aradszki
Hi thanks for the fast replay!

Hm mayby I'm stupid ;).

Now let me tell me more:
I use your Version 0.8.1
2 things I have changed:

1. in the display-function I changed the echo to return (I need a return of the value and no output)

2. in the validator-function I dissabled the including file if. I put the validation-Class in the same script.

all works fine.
------------------------------------------------------

And now I put your "public function password($pass1, $aux, $data)" to the validation-Class. Right?
I put after all addItem addField etc the validation:

$form->validator("passw1", "password")
Right?

after I test it I get

Warning: Missing argument 3 for Validator::password(), called in ...
(the LineNr. from $this->error($id, $this->validator->{$validatorFunc}($value, array_slice($args, 2)),$this->input);
from protected function validateFields())
and defined in
(the lineNr. from public function pwVali($pass1, $aux, $data)).

Is the problem in:
protected function validateFields()
....
$this->error($id, $this->validator->{$validatorFunc}($value, array_slice($args, 2)),$this->input);

Or to me?

Thanks for solution!

  4. Re: Compare two values   Reply   Report abuse  
Picture of Bertol, Alexander Bertol, Alexander - 2011-07-05 11:15:03 - In reply to message 3 from Bertol, Alexander
Hi again,

I fixed the error:

You have to change the line 461 in formgenerator from

$this->error($id, $this->validator->{$validatorFunc}($value, array_slice($args, 2)),$this->input);

to

$this->error($id, $this->validator->{$validatorFunc}($value, array_slice($args, 2),$this->input));

and now it works greate!

;)

  5. Re: Compare two values   Reply   Report abuse  
Picture of Gergely Aradszki Gergely Aradszki - 2011-07-14 12:29:24 - In reply to message 4 from Bertol, Alexander
Hi!

Yes, it's bit embarassing, I found the error too, I'll post the updates soon. In the meantime, a fetch method has been added, so you will be able to get the form instead of printing it without modifying the code)

As for the "validator class in the same file" issue, I think I'll add a class_exists check before including the file, although I prefer the "one class one file" method, but this check wouldn't hurt anymody:D