Validate a form element in dependence of the value of another element

eulanaz

Member
Hi all,

I have a problem with validation and I didn't found any solution.

Here the situation:

I have a group in a form with more elements and related validations.

I have an element with a validation that makes a query to the DB and validate the input with the results. Until here, no problem. My issue is that I need to leave out the validation based on another element. Can I do that with the PHP eval?

For example:

Element A - INT
Element B - STRING

DB value presents for column A: {1,2,3,4,5,6,7,8,9}

In the "ADD" form I need the following behaviour for the validation:

- A must be different to {1,2,3,4,5,6,7,8,9} (already exists on DB)
- If B is equal to "SPECIAL", A can have any value including.

How can I validate A and in the same time check the value in B?

Thanks in advance

eulanaz
 
Easiest way would be to use a Condition on the validation, using a placeholder for element B's value ...

PHP:
return '{yourtable___elementB}' !== "SPECIAL";

This will return 'false' if element B is "SPECIAL", which will stop the validation form running.

-- hugh
 
Hi cheesegrits,

thanks a lot for your support.

It works!!!!

First, without using the condition form but the PHP code no data was captured with the following line:

$Bfield = JRequest::getVAR('id_of_the_field');

Thanks again

eulanaz
 
That's because our inputs use the full element name, with the tablename___ prefix.

Also note that JRequest has been deprecated, you should use either our form model, or JFactory::getApplication()->input.

-- hugh
 
Hi cheesegrits,

thanks for your informations.

I noticed now that on my production did not works as expected. In my local version everything works fine but not on the public portal.

It seems to be that the condition "'{yourtable___elementB}' !== "SPECIAL";" is verified by every element! I'm no more able to set any value without insert "SPECIAL" on elementB.

This is very strange.... Have you a suggestion?

Thx
eulanaz
 
Hi cheesegrits,

sorry. False alarm. I tried to reconfigure everything in my form from zero (directly on the production environment) and now everything work fine!

eualanaz
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top