i am using exceptions in my user class .when i catch them the message is automatically displayed and form goes to my header if i leave fields empty . what should i do ??? here is my class code : <?php class usernew1 { private $firstName; private $middleName; public function __construct() { } public function __set($name,$value) { $method = "set_".$value; if(!method_exists($this, $method)) { throw new Exception("property does not exist ..."); } $this->$method($value); } public function __get($name) { $method = "get_".$name; if(!method_exists($this,$method)) { throw new Exception("property does not exist..."); } return $this->$method(); } private function set_firstName($firstName) { $reg = "/^[a-z]+$/i"; if(!preg_match($reg, $firstName)) { throw new Exception("missing /invalid first name ...."); } $this->firstName =$firstName; } private function get_firstName() { return $this->firstName; } } ?> next is my process page to catch exceptions process: <?php require_once("usernew1.php"); session_start(); $objuser = new usernew1(); $errors = array(); try { $objuser->__set("firstName",$_POST['firstName']); } catch(Exception $ex) { $errors['firstName'] = $ex->getMessage(); } ?> and in the end form is here ..... <?php //require_once("webinterface.php"); require_once("usernew1.php"); session_start(); if(isset($_SESSION['errors'])) { $errors = $_SESSION['errors']; } else if(isset($_SESSION['objuser'])) { $objuser = unserialize($_SESSION['objuser']); } else { $objuser = new usernew1(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>User Registration</title> <link href="styles/newUserStyles.css" type="text/css" media="all" rel="stylesheet" /> </head> <body> <div id="formContainer"> <div id="headingRow">New User Registration</div> <form action="process.php" method="post" enctype="multipart/form-data" id="userForm"> <div class="row"> <div class="cell cellLeft">First Name</div> <div class="cell cellRight"> <input type="text" id="firstName" name="firstName" value=""/><span id="firstNameError"> <?php if(isset($errors['firstName'])) { echo($errors['firstName']); } ?></span></div><div class="clearBox"></div> <div class="clearBox"></div> <div class="row c2" style="text-align:center;"> <input type="submit" value="Register" /></div> </form> </div> </body> </html> kindly help me and poin out my mistakes here . i am new in php. thanks in advance
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)