I was hoping to get some advice on why the code below is not working as expected. At the moment I am working on making sure that the name in the form is not empty, when the form is submitted.
The particular snip bit I am talking about is - <code> elseif(($key === 'name'&& !empty($formatedValue))|| $key === 'other'){ echo 'hi'; if(!preg_match("/^[A-Za-z -]{3,30}\$/",$formatedValue)){ $message = $key.' should only contain letters and should be no longer than 45 characters'; } } </code>
the code below in full - <code> <?php function sendEmail($email){ $headers ="MIME-Versin: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8; format=flowed\r\n" . "Content-Transfer-Encoding: 8bit\r\n" . "From:" .$email['email']. "\r\n" . "X-Mailer: PHP" . phpversion();
mail("bfishdesign@gmail.com","Query",$emails,$headers); echo "Thank you for your enquiry. We will get back to you as soon as possible"; } function checkEmail($email){ if(!preg_match("/^[A-Za-z]+[1-9]*([.][A-Za-z]+)?[@][A-Za-z]+[.][A-Za-z]{2,3}([.][A-Za-z]{2,3})?\$/",$email)){ return false; }else return true; }
function formatInput($toFormat){ if(get_magic_quotes_gpc()){ $toFormat = stripslashes($toFormat); $toFormat = trim(strip_tags((string) $toFormat)); }else{ $toFormat = trim(strip_tags((string) $toFormat)); } return $toFormat; } //do some error checking on user input function checkValues($key,$check){ $message = ''; $formatedValue = formatInput($check); if($key === 'submited' || $formatedValue === '' || is_array($formatedValue)) ; elseif(($key === 'name'&& !empty($formatedValue))|| $key === 'other'){ echo 'hi'; if(!preg_match("/^[A-Za-z -]{3,30}\$/",$formatedValue)){ $message = $key.' should only contain letters and should be no longer than 45 characters'; } } elseif($key === 'email'){ $email = checkEmail($formatedValue); if($email == 0){ $message = 'email error'; } } elseif($key === 'post'){ if(!is_numeric($formatedValue) || strlen($formatedValue) != 4) $message = $key .' error'; } elseif($key === 'phone' || $key === 'mobile'){ if(!is_numeric($formatedValue) || strlen($formatedValue) != 10) $message = $key .' error'; } return $message; } //convert array into individual variables function separateArray($array){ foreach($array as $key => $val){ if(is_array($val)) ;//separateArray($array[$key]); else{ $check = checkValues($key,$array[$key]); if (!empty($check)) $errors[$key] = $check; }