You can do this programmatically as follows:
class email { //Expressions public static $errorOccuredInCurrentRun = false; const exp_name = "/^[A-Za-z .'-]+$/"; const exp_email = '/^[A-Za-z0-9._%-] +@ [A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; const error = "We are sorry, but there appears to be a problem with the form you submitted.<br/>"; private $msg = 'Thank you for subscribing'; protected $status = true; public static function factory(){ //du your validation self::$errorOccuredInCurrentRun = false; self::validate(); if(!self::$errorOccuredInCurrentRun){ return new Email(); }else{ return null; } } private function __construct() { echo '<br/>the CLASS continued</b><br/>'; } private static function validate() { //Empty fields foreach ($_REQUEST as $key => $value) { if(self::$errorOccuredInCurrentRun){ break; } $val = str_replace(' ', '', $value); if ($val === '') { self::error('empty', $key); self::kill(); //If empty, this should end the loop and class } //if:empty } //foreach //Validate Name if(self::$errorOccuredInCurrentRun){ if (!preg_match(self::exp_name, $_POST['Name'])) { self::error('name'); self::kill(); //kill //Validate e-Mail if(self::$errorOccuredInCurrentRun){ if (!preg_match(self::exp_email, $_POST['e-Mail'])) { self::error('email'); self::kill(); //kill } } } } } public function status() { return $this->status; } public function msg() { return $this->msg; } private function error($type = null, $value = null) { switch ($type) { case 'empty': $this->msg = self::error . "<div class='error'><b>The following field is empty: </b>" . $value . "</div>"; self::set(false); break; case 'name': $this->msg = self::error . "<div class='error'><b>The First Name you entered does not appear to be valid.</b></div>"; self::set(false); break; case 'email': $this->msg = self::error . "<div class='error'><b>The e-Mail you entered does not appear to be valid.</b></div>"; self::set(false); break; default: self::set(false); $this->msg = self::error; } return; //kill app } private function set($boolean = false) { $this->status = $boolean; } private function kill() { self::$validationRunCompleted; } }
and then use it like this:
$email = email::factory(); if(is_null($email)){ //something went wrong }else{ //validation was fine }
i is executed only if the current "start" does not contain errors. And only if there were no errors, you yourself received an e-mail object so that you can continue and do what you need.
source share