ContactForm.php - function validateInput($data $fieldName...

This preview shows page 1 - 3 out of 3 pages.

function validateInput($data, $fieldName) { global $errorCount; //declared global variable if (empty($data)) { // the if statement states if $data is empty it will echo provided below. echo "\"$fieldName\" is a required field. \n"; //echo statement ++$errorCount; // if theres a n error it will add to the error count. $retval = ""; } else { $retval = trim($data); //trim function removes the whitespaces from $data. $retval = stripslashes($retval);// will strip the backslashes off variable $retval. } return($retval); // returns variable $retval. } //this function takes 2 parameters, $ data which is a string to validated and $fieldname which is the name of the field in the form. function validateEmail($data, $fieldName) { global $errorCount; // declared global variable if(empty($data)) { //if $data is empty, it will echo statement provided below. echo "\"$fieldName\" is a required field. \n"; ++$errorCount; $retval = ""; } else { //if data is not empty it will filter and sanitize the data. // if the email address is not in valid format, this function will echo the statement provided below $fieldName $retval = filter_var($data, FILTER_SANITIZE_EMAIL); if(!filter_var($retval,

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture