Sum validation
-
Hi there!
I’m trying to insert an error message whether the sum of some input fields is greater than a certain number.
More specifically, the contact form is to enquire about the vacancy of hotel room.
For each room, I need to know how many people/pets are going to be in that room.
Of course, there is a limit to it, and that is 4 people/pets.I’d like to insert an error message anytime they try to book a room for more than 4 people/pets.
In the contact form, it would be something like:
<label> Adults* [select* r1-adults "1" "2" "3" "4"] </label> <label> Children* [select* r1-children "0" "1" "2" "3"] </label> <label> Babies* [select* r1-babies "0" "1" "2" "3"] </label> <label> Pets* [select* r1-pets "0" "1" "2" "3"] </label>
In the functions.php:
add_filter( 'wpcf7_max_capacity*', 'custom_max_capacity_validation_filter', 20, 2 ); function custom_max_capacity_validation_filter( $result, $tag, $adults, $children, $babies, $pets ) { $tag = new WPCF7_FormTag( $tag ); $adults=$_POST['r1-adults']; $children=$_POST['r1-children']; $babies=$_POST['r1-babies']; $pets=$_POST['r1-pets']; $sum=( $adults+$children+$babies+$pets); return $sum; if ($sum > "4" ) { $result->invalidate( $tag, "Rooms cannot accomodate more than 4 people/pets" ); } return $result; }
It does not work, and I cannot find a way to solve the syntax.
Can you help me, please? I would really appreciate it!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Sum validation’ is closed to new replies.