From: zia mohaddes on
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
From: Mark Steudel on
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(a)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(a)gmail.com

.. : Work : .
http://www.mindfulinteractive.com

.. : Play : .
http://www.steudel.org/blog