Re: addrule
| From: | Mark Steudel | Date: | Tue, 18 May 2010 21:44:17 +0000 |
| Subject: | Re: addrule | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30545@lists.php.net to get a copy of this message | ||
Are you referring to using HTML_QuickForm package?
If so you can use a formRule
e.g.
function checkQuestions( $fields ) {
if( ( ( $fields['question1'] + $fields['question2'] ) < 100 ) &&
strlen( $fields['question3'] ) == 0 ) {
$errors['question3'] = 'Question 3 is required if questions 1
and questions 2 add up to less than 100';
}
return count( $errors ) > 0 ? $errors : true;
}
$form = new HTML_QuickForm( 'form' );
$form->addFormRule( 'checkQuestions' );
$form->addElement( 'text', 'question1', 'Q1: ' );
$form->addElement( 'text', 'question2', 'Q2: ' );
$form->addElement( 'text', 'question3', 'Q3: ' );
(double check my synxtax, but that's one way to do this)
Mark
On Tue, May 18, 2010 at 2:34 PM, zia mohaddes <zia.simab@gmail.com> wrote:
> Hello everyone,
>
> I had a quick question regarding rules.
>
> I want to set the following rule for a question( let's say):
>
> question3 is required if (question1+ question2) <100.
> I am wondering if I could do something like this with addrule. I know
> addrule only takes Boolean values, but I am wondering if there is any way to
> perform arithmetic operations with addrule?
>
> Thank you kindly for your help in advance!
>
>
> regards,
>
> zia
>
--
-----------------------------------------
Mark Steudel
P: 206.375.7244
msteudel@gmail.com
. : Work : .
http://www.mindfulinteractive.com
. : Play : .
http://www.steudel.org/blog