Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2008, 02:32 AM
kmg kmg is offline
Junior Member
 
Join Date: Mar 2008
Posts: 9
Default Zend_Validate_Identical not working.

I can't get Zend_Validate_Identical to work. It just always says "No token was provided to match against", no matter what.

PHP Code:

        $form
->addElement('text''first'
            array(
                
'required'    => true,
                
'label'        => 'First Name',
                
'validators'    => array(
                    
'alnum',
                    array(
'StringLength'503),
                    array(
'regex'false'/^[a-zA-Z]/i'),
                    array(
'Identical''test')
                    ),
                )
            ); 
So what's the deal?

Also, I need to compare one form field to another form field (password to confirm password), and the easiest way I could think while following the validation model was to write a custom validator, something like Zend_Validate_IdenticalToField that would just take in a form element, and call it's getValue method for comparison. Is there some better way this could be implemented within the Zend_Form / Zend_Validate pattern? Also, what about a UniqueInModelField validator that checks against a model for any existing entries that would conflict, like for a unique email address? These are probably outside of the scope of Zend_Validate by quite a bit though. What do you guys think?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-05-2008, 04:40 PM
Junior Member
 
Join Date: May 2008
Posts: 4
Default

you should use this:
array('Identical', $variable)

if you set 'test', the validator compares text from your input field with the 'test' word

if you have input field named 'test', you should write something like that:

array('Identical', $this->getRequest()->getParam('test'))

in other words:
Code:
//password entered in the form
$password = $this->getRequest()->getParam('password'); 

//repeat password field in your form
$form->addElement('password', 'repeat_password', 
        array(
                //...
                'validators'    => array(
                 //...
                    array('Identical', $password)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-21-2008, 11:03 AM
Junior Member
 
Join Date: May 2008
Posts: 1
Default

Hi,

I am currently having the same problem and the solution you are provided doesnt work. Any clue ?

I get the "No token was provided to match against".

Thanks for your help.

Pascal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-22-2008, 09:56 AM
Junior Member
 
Join Date: Apr 2008
Posts: 28
Default

I solved it this way.

NOTE: - $context['wachtwoordA] is the name of the first passwordfield
- $value is the value of the field which it is validating.
- This is the isValid method from my own custom validator

Code:
    public function isValid($value, $context = null)
    {
        $value = (string) $value;
        $this->_setValue($value);

      	  if (is_array($context))
      	   {
      	      if (isset($context['wachtwoordA'])
     	           && ($value == $context['wachtwoordA']))
     	       {
    	            return true;
    	       }
      	   }
          elseif (is_string($context) && ($value == $context))
           {
            return true;
           }
         
        $this->_error(self::NOT_MATCH);
        return false;
    }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-10-2008, 06:01 PM
Junior Member
 
Join Date: Aug 2008
Posts: 2
Default A more generic solution...

Greetings All,

I have created a more generic solution to this problem, allowing one to validate any field against any other field (e.g. make sure passwords match, emails match, value match captcha challenge, etc.). I couldn't seem to get the markup on this page to look right, so I've provided the code at the this link along with example usage. Enjoy!

Sean P. O. MacCath-Moran
Welcome | emanaton dot com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-30-2008, 09:17 PM
Junior Member
 
Join Date: Aug 2008
Posts: 1
Default

Hi,

I ran into the same problems. I tried to fix it like this

PHP Code:
$password2        = new Zend_Form_Element_Password('password2');
$password2->setLabel('Repeat password')
            ->
setRequired(true)
            ->
addValidator(new Zend_Validate_Identical($_POST['password'])); 

This seems to work just fine, at least for me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-15-2008, 11:34 PM
Junior Member
 
Join Date: Aug 2008
Posts: 7
Default

Quote:
Originally Posted by emanaton View Post
Greetings All,

I have created a more generic solution to this problem, allowing one to validate any field against any other field (e.g. make sure passwords match, emails match, value match captcha challenge, etc.). I couldn't seem to get the markup on this page to look right, so I've provided the code at the this link along with example usage. Enjoy!

Sean P. O. MacCath-Moran
Welcome | emanaton dot com
Thanks was looking for the same thing. Works great
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-06-2008, 12:18 PM
Junior Member
 
Join Date: Aug 2008
Posts: 2
Default

Quote:
Originally Posted by hastinbe View Post
Thanks was looking for the same thing. Works great
Woot! =o)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:46 PM.