javascript - check if input value not equal to integer then don't submit form -
i have simple php email form, getting spam emails. have added check input, user have fill input. if input value equal 12 submit form, otherwise don't submit form popup error.(please math.)
<form action="" method="post"> <input type="text" name="name" placeholder="name" required> <input type="text" name="email" placeholder="email" required> <input type="text" name="phone" placeholder="phone" required> <div class="check"> <label>6 x 2 =</label> <input type="text" name="not_robot" required="required"> </div> <input type="submit" value="submit"> </form>
i using php method below:
if(isset($_post['not_robot']) !== 12 && isset($_post['not_robot']) !== ''){ echo '<script type="text/javascript">alert("please math, if human.");</script>'; }else{ //email script here }
when submit form, error popup appear saying "please math, if human", after close popup, send email. appreaciated thanks
p.s: if check method possible using javascript or jquery great help.
try check when submitting form. go below code or link-
html code-
<form action="" method="post"> <input type="text" name="name" placeholder="name" required> <input type="text" name="email" placeholder="email" required> <input type="text" name="phone" placeholder="phone" required> <div class="check"> <label>6 x 2 =</label> <input type="text" name="not_robot" required="required"> </div> <input type="submit" value="submit"> </form>
javascript code-
$('form').submit(function() { if (parseint($('input[name="not_robot"]').val()) == 12) { return true; } else{ alert('you not enterd correct value'); return false; } });
Comments
Post a Comment