コード例 #1
0
 /**
  * validateEmail
  *
  * Validate new portfolio
  * @param($_POST)
  * @return(boolean)
  */
 public function validateEmail()
 {
     # create empty error
     $aErrors = array();
     # validate name
     if (strlen($_POST['name']) >= 30) {
         $aErrors['name'] = true;
     }
     # validate email
     if (!Filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
         $aErrors['email'] = true;
     }
     # validate subject
     if (strlen($_POST['subject']) >= 30) {
         $aErrors['subject'] = true;
     }
     # validate message
     if (strlen($_POST['message']) >= 1000) {
         $aErrors['message'] = true;
     }
     # if errors return them
     if ($aErrors) {
         return $aErrors;
     } else {
         return true;
     }
 }
コード例 #2
0
 /**
  * mutator method for the user last name
  *
  * @param string $newUserLastName string of users last name
  * @param \InvalidArgumentException if $newUserLastName is not a string
  * @param \RangeException if $newUserLastName is > 32
  * @param \TypeError if $newUserLastName is not a string
  */
 public function setUserLastName(string $newUserLastName)
 {
     //verify userFirstName is secure
     $newUserLastName = trim($newUserLastName);
     $newUserLastName = Filter_var($newUserLastName, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     if (empty($newUserLastName) === true) {
         throw new \InvalidArgumentException("user first name is empty or not secure");
     }
     //verify user first name will fit in database.
     if (strlen($newUserLastName) > 32) {
         throw new \RangeException("user first name too large");
     }
     //store the user first name
     $this->userLastName = $newUserLastName;
 }