Cross field form validation
-
I need to compare and validate two text fields to make sure at least one of them says “Washington, DC”.
[text* pick-up-location] [text* drop-off-location]
If one of them doesn’t I need to highlight both fields and return an error message saying, ‘One of these fields must be: “Washington, DC”‘.
I got some hints from the code by @kzeni in this thread which checks the field to see if the email address is from a certain domain.
I can see from this code how to check one text field, then return the error message right inside
if
statement:if($name == 'company-email'){ $the_value = $_POST[$name]; if(!is_company_email($the_value)){ $result['valid'] = false; $result['reason'][$name] = 'You need to provide an email address that isn\'t hosted by a free provider.<br />Please contact us directly if this isn\'t possible.'; } }
but I don’t understand how to:
* get the value from two separate elements
* compare them with the target string
* return error messages on each input fieldAny idea whether this is possible?
- The topic ‘Cross field form validation’ is closed to new replies.