Form validation before email is sent input type date etc.
4 posts by 3 authors in: Forums > CMS Builder
Last Post: October 15 (RSS)
By Twocans - October 15
Hi all,
I have a problem with form validation before email is sent.
https://www.4fratellicaprini.co.uk/reservations.php
some fields validate but the bottom 3 don't validate. If i get rid of the validation and submit then the input of those form files do work etc, but i want to be sure the punter fills them in.
<input type="date" class="form-control" name="dateofbooking" id="dateofbooking" value="<?=htmlspecialchars(@$_REQUEST['dateofbooking']);?>
<input type="time" class="form-control" name="timeofbooking" id="timeofbooking" value="<?=htmlspecialchars(@$_REQUEST['timeofbooking']);?>
<input type="text" class="form-control" name="howmany" id="howmany" value="<?=htmlspecialchars(@$_REQUEST['howmany']);?>
and when the form is submitted I get the errors
'Date of Booking' is required.
'Time of Booking' is required.
'How Many' is required.
### ERROR CHECKING
list($table, $num) = [$FORM_TABLE, $FORM_RECORD_NUM]; // assign shorter convenience variables
if (@$_REQUEST['name'] == '') { $errorsAndAlerts .= "'Name' is required.<br>\n"; }
if (@$_REQUEST['phone'] == '') { $errorsAndAlerts .= "'Phone' is required.<br>\n"; }
if (@$_REQUEST['email'] == '') { $errorsAndAlerts .= "'Email' is required.<br>\n"; }
if (@$_REQUEST['date_of_booking'] == '') { $errorsAndAlerts .= "'Date of Booking' is required.<br>\n"; }
if (@$_REQUEST['time_of_booking'] == '') { $errorsAndAlerts .= "'Time of Booking' is required.<br>\n"; }
if (@$_REQUEST['how_many'] == '') { $errorsAndAlerts .= "'How Many' is required.<br>\n"; }
Am grateful for any input.
cheers
kenny
By Tim - October 15
Hello Kenny,
I have addressed the issues with you via email. Just let me know if you experience any other problems.
Thanks!
Senior Web Programmer
Interactivetools.com
By Djulia - October 15
Hi Kenny,
In your HTML input fields, the names are dateofbooking, timeofbooking, and howmany. However, in your error checking logic, you are referencing date_of_booking, time_of_booking, and how_many. This mismatch will cause the validation to fail because the script is looking for different names than what the form is submitting.
Here’s how you can adjust your error checking code:
// Adjust field names in your validation checks
if (@$_REQUEST['name'] == '') { $errorsAndAlerts .= "'Name' is required.<br>\n"; }
if (@$_REQUEST['phone'] == '') { $errorsAndAlerts .= "'Phone' is required.<br>\n"; }
if (@$_REQUEST['email'] == '') { $errorsAndAlerts .= "'Email' is required.<br>\n"; }
if (@$_REQUEST['dateofbooking'] == '') { $errorsAndAlerts .= "'Date of Booking' is required.<br>\n"; }
if (@$_REQUEST['timeofbooking'] == '') { $errorsAndAlerts .= "'Time of Booking' is required.<br>\n"; }
if (@$_REQUEST['howmany'] == '') { $errorsAndAlerts .= "'How Many' is required.<br>\n"; }
By making these adjustments, your form validation should start working as expected.
Cheers!
Djulia
By Twocans - October 15
Hi TIm
Thank you very much for being so professional, have a lovely evening.
regards
k