Note that there are some explanatory texts on larger screens.

plurals
  1. POcant figure out php contact form verification woes
    primarykey
    data
    text
    <p>Hi I got a contact from script the internet that I have been messing around with, only problem is that the verification that I am trying to add to it just doesn't work. Basically in the form it has name, email, number, type and comment. My main verification woes are with the number field I would like it so that if it is empty it echos "no number" and when the person type in letters instead of numbers it will echo "you need to type with numbers". Something like lol. but I’m stuck. Can any of you geniuses help me? Thanks in advance here is the full code below. p.s. sorry about previous post i accidently cut off the script:$</p> <pre><code>&lt;?php $nowDay=date("d.m.Y"); $nowTime=date("H:i:s"); $subject = "E-mail from my site!"; if (isset($_POST['submit'])) { //contactname if (trim($_POST['name'] == '')) { $hasError = true; } else { $name = htmlspecialchars(trim($_POST['name'])); } //emailaddress if (trim($_POST['email'] == '')) { $hasError = true; } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i",trim($_POST['name']))) { $hasError = true; } else { $email = htmlspecialchars(trim($_POST['email'])); } //phonenumber if (trim($_POST['number'] == '')) { $fake_num = true; } else if(!is_numeric($_POST['phonenumber'])) { $fake_num = true; } else { $number = htmlspecialchars(trim($_POST['number'])); } //type $type = trim($_POST['type']); //comment if (trim($_POST['comment'] == '')) { $hasError = true; } else { $comment = htmlspecialchars(trim($_POST['comment'])); } if (!isset($hasError) &amp;&amp; !isset($fake_num)) { $emailTo = 'email@hotmail.com'; $body = " Name: $name\n\n Email: $email\n\n Phone number: $number\n\n Type: $type\n\n Comment: $comment\n\n \n This message was sent on: $nowDay at $nowTime"; $headers = 'From: My Site &lt;'.$emailTo.'&gt;'."\r\n" .'Reply-To: '. $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?&gt; &lt;?php if(isset($hasError)) { echo"&lt;p&gt;form has error&lt;/p&gt;"; } ?&gt; &lt;?php if(isset($fake_num)) { echo"&lt;p&gt;wrong num&lt;/p&gt;"; } ?&gt; &lt;?php if(isset($emailSent) &amp;&amp; $emailSent == true) { echo "&lt;p&gt;&lt;strong&gt;Email Successfully Sent!&lt;/strong&gt;&lt;/p&gt;"; echo "&lt;p&gt;Thank you &lt;strong&gt; $name &lt;/strong&gt; for using my contact form! Your email was successfully sent and I will be in touch with you soon.&lt;/p&gt;"; } ?&gt; &lt;div id="stylized" class="myform"&gt; &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" name="bookingform" id="bookingform"&gt; &lt;h1&gt;Booking form&lt;/h1&gt; &lt;label&gt; Name &lt;span class="small"&gt;&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="name" id="name" class="required"/&gt; &lt;label&gt; Your email: &lt;span class="small"&gt;&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="email" id="email" class="required"/&gt; &lt;label&gt; Contact Number: &lt;span class="small"&gt;&lt;/span&gt; &lt;/label&gt; &lt;input type="text" name="number" id="number" class="required" /&gt; &lt;label&gt; Car required: &lt;span class="small"&gt;&lt;/span&gt; &lt;/label&gt; &lt;select name="type" id="type"&gt; &lt;option selected="selected"&gt;Manual&lt;/option&gt; &lt;option&gt;Automatic&lt;/option&gt; &lt;/select&gt; &lt;label&gt; Comment: &lt;span class="small"&gt;&lt;/span&gt; &lt;/label&gt; &lt;textarea cols="" rows="" name="comment" id="comment" class="required"&gt;&lt;/textarea&gt; &lt;button type="submit" name="submit"&gt;Submit&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; </code></pre>
    singulars
    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.
 

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