Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to apply Server Side Validation on form in Cakephp

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 858
    Comment on it

    Data validation is the process to ensure that computer input coming from user is clean, correct and useful. Data validation also checks if field is not empty. If validation fails , response is sent back to the user, then display proper message, so that user can fill the form properly. In the server-side validation, information will sent to the server and then validated using server-side language like php.


    Form validation occur at the server, after the user had filled all the fields and pressed the Submit button. If the data entered by a user was incorrect or some data is missing, the server would have to send all the data back to the user and request to fill the form with correct information and then resubmit it . The code for server side validaton in cakephp is written below:

     

    The following code should be copied in your model (User.php)

     

     

    
    var $validate = array(
    		'email'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing Email'
    			)
    		),
    	'password'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing Password'
    			)
    		),
    	'password_confirm' => array(
    		'required'=>'notEmpty',
    		'match'=>array( 
    			'rule' => 'validatePasswdConfirm', 
    			'message' => 'Passwords do not match'
    			)
    		),
    	'firstname'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing First Name'
    			)
    		),
    	'lastname'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing last Name'
    			)
    		),
    
    	'address'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing Address'
    			)
    		),
    	
    	'riderimage'=>array(
    		'required'=>array(
    			'rule'=>'notEmpty',
    			'message'=>'Missing Image'
    			)
    		),
    
       
    	) ;
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: