Re: QuickForm rule needs other submittedValues

From: Date: Thu, 22 May 2003 15:50:57 +0000
Subject: Re: QuickForm rule needs other submittedValues
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-5551@lists.php.net to get a copy of this message
<wolfram@visionp.de> wrote : > i have written a rule, which i register using registerRule(). > This rules checks if the email is unique. But what i need for this to > properly do the work is the ID, which is another one of the submitted > values. But as i see it i have no chance to access any other data of > the form from within my rule-function. Or is there a way? > > this is my rule-function. > > function isEmailUnique($email) > { > $user =& new Dao_User(); > $user->setWhere('LOWER(email)='.$email); > $user->addWhere('id<>'.????user-ID????); > return $user->getCount()>0?false:true; > } > > here i need access to other submitted values. is that possible? or how > do i do it best? There are different ways to do that. 1. You validate a group, not an element. This way, every values from the group will be passed to the validation function. 2. You use the format parameter of your addRule() method: $form->addRule('email', 'Email is not unique', 'isEmailUnique', $form->getSubmitValue($userId)); then change your function to : function isEmailUnique($email, $userId) 3. You make $form global in your function... Good luck, Bertrand

« previous php.pear.general (#5551) next »