The following php form validation code does not work properly. Can anyone figure this out? Is it a duplicate attribute issue?
<$php
if ($_POST['submit'])
{
$name = $_POST['name'];
$phone = $_POST['phone'];
$errorstring = "";
if (!$name)
$errorstring = $errorstring."name<br>";
if (!$phone)
$errorstring = $errorstring."phone<br>";
if ($errorstring!="")
echo "Please fill out the following fields:<br>$errorstring";
{
//run code
die("success!");
}
}
$>
You can’t handle checkboxes likeyou are text inputs. When a checkbox is not checked a value for it doesn’t exist. So what you need to do is see if a value exists and if not use a placeholder to differentiate unchecked from checked.
Thanks! It successfully checks the box on the reloaded page. For some reason the rule that states if the checkbox has been checked then the auto section of the form will expand does not work, but when I uncheck the checkbox on the reloaded page the auto form appears, which is the opposite of what it should do.
When a visitor submits the form without filling in the required information it reloads the same page upon them pressing submit. However, when the page loads after them pressing submit the checkbox is no longer checked. There is a php rule that states if the checkbox is not checked the form will not validate or send properly, so when they send the form again after filling in the fields they missed the first time the form doesn’t send properly. I need the checkbox to be checked on the page that follows after the user presses submit the first time on the form. Here is some of the form code: