Note that there are some explanatory texts on larger screens.

plurals
  1. POI cannot get my PHP Form Validation working
    primarykey
    data
    text
    <p>Ok guys, I have do this quit some time, but now it seems I cannot get this thing working; it has been 2 days, and I'm going nuts over this</p> <p>here is the form:</p> <pre><code>&lt;form id="contact" action="#" method="POST"&gt; &lt;label id="name"&gt;Full Name &lt;span class="star"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input id="name" type="text" name="name" /&gt; &lt;label id="phone"&gt;Phone &lt;/label&gt;&lt;input id="phone" type="text" name="phone" /&gt; &lt;label id="address1"&gt;Address Line 1 &lt;/label&gt;&lt;input id="address1" type="text" name="address1" /&gt; &lt;label id="address2"&gt;Address Line 2 &lt;/label&gt;&lt;input id="address2" type="text" name="address2" /&gt; &lt;label id="city"&gt;City &lt;/label&gt;&lt;input id="address1" type="text" name="city" /&gt; &lt;label id="state"&gt;State/Province &lt;/label&gt;&lt;input id="state" type="text" name="state" /&gt; &lt;label id="zip"&gt;Zip Code &lt;/label&gt;&lt;input id="zip" type="text" name="zip" /&gt; &lt;label id="email"&gt;Email &lt;span class="star"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;input id="email" type="text" name="email" /&gt; &lt;label id="comments"&gt;Comments &lt;/label&gt;&lt;textarea rows="4" cols="53" id="comments" name="comments"&gt;&lt;/textarea&gt; &lt;input type="submit" name="submitForm" value="SUBMIT" id="submitForm" /&gt; &lt;/form&gt; </code></pre> <p>Here is the php code:</p> <pre><code>&lt;?php if(isset($_POST['submitForm'], $_POST['name'], $_POST['email'], $_POST['phone'], $_POST['address1'], $_POST['address2'], $_POST['city'] , $_POST['state'], $_POST['zip'], $_POST['comments'])){ // get data from form // no spaces $email = $_POST['email']; $email = trim($email); $email = htmlspecialchars($email); $name = $_POST['name']; $name = trim($name); $name = htmlspecialchars($name); $phone = $_POST['phone']; $phone = trim($phone); $phone = htmlspecialchars($phone); $address1 = $_POST['address1']; $address1 = trim($address1); $address1 = htmlspecialchars($address1); $address2 = $_POST['address2']; $address2 = trim($address2); $address2 = htmlspecialchars($address2); $city = $_POST['city']; $city = trim($city); $city = htmlspecialchars($city); $state = $_POST['state']; $state = trim($state); $state = htmlspecialchars($state); $zip = $_POST['zip']; $zip = trim($zip); $zip = htmlspecialchars($zip); $comments = $_POST['comments']; $comments = trim($comments); $comments = htmlspecialchars($comments); // error array $errors = array(); // check to see if email or name field are empty if(empty($email) || empty($name)){ $errors[] = "Email or Name fields must be completed before submitting"; } else { if(strlen($name) &lt; 2){ $errors[] = "Full Name Field: Full name is too short"; } else if (!preg_match('/^[a-zA-Z\- ]*$/', $name)){ $errors[] = "First Name Field: Only alphabets and hyphens are allowed"; } else { // do nothing } // validating email address if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE){ $errors[] = "Email Field: Please enter a valid email address"; } } // if $errors are not empty, diplay error message if(!empty($errors)){ foreach($errors as $error){ echo "&lt;div id=\"phperrorsContact\"&gt;" . $error . "&lt;/div&gt;&lt;br /&gt;"; } } else { // if there are no errors, sned email to staff and client } } // end of isset ?&gt; &lt;/div&gt; </code></pre> <p>The only two fields that I need to validate are the full name field and email field. When both fields are empty, my validation kicks in, but when I type in a wrong email address, it doesn't work. Or if I type in one character in full name, it doesn't work either. In case you are wondering, the form's values will not be submitted to a database, so no need to do any sql injection validation.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload