php - Basic Form Validation Check Number? -


in script checking if fields not empty , email address syntactically correct. how add text input @ bottom of form basic sum question, e.g. (2+5)= want add validation element current script check if equals 7.

if (empty($name) || empty($phone) || empty($email) || empty($enquiry)) {     echo "    * sorry fields required."; } elseif(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email))  {     print "<p>sorry email address entered looks it's invalid.</p>"; } else {     mail($to, $sub, $mes, $headers);     print "<p>thank ".$name." contacting us.<br /><br />we in touch shortly.</p>";  } 

if wanting validate static sum, e.g. know going ( 2 + 5 ) = 7

then write simple function check posted value.

// being posted value; $validate = 7;   function sumcheck($value){      if ( 2 + 5 == $value ){         return true;     }     else{         return false;     }  } 

then change initial line to;

if (empty($name) || empty($phone) || empty($email) || empty($enquiry) || !sumcheck($validate)) 

however, suggest using recaptcha robert podwika has suggested.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -