Advertisement
Guest User

Model Validation File12

a guest
Jan 30th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. Model File Code:
  2. <?php
  3. App::uses('Model', 'Model');
  4.  
  5. /**
  6.  * Application model for Cake.
  7.  *
  8.  * Add your application-wide methods in the class below, your models
  9.  * will inherit them.
  10.  *
  11.  * @package       app.Model
  12.  */
  13. class User extends Model {
  14.     public $name = 'User';
  15.     public $validate = array(
  16.         'fname' => array(
  17.             'rule'      => 'notEmpty',
  18.             'required'  => true,
  19.             'message'   => 'Please fill first name.'
  20.         ),
  21.         'uname' => array(
  22.             'rule'      => 'notEmpty',
  23.             'required'  => true,
  24.             'message'   => 'Please fill Username name.'
  25.         ),
  26.         'email' => array(
  27.             'rule'      => 'notEmpty',
  28.             'required'  => true,
  29.             'message'   => 'Please fill email.'
  30.         ),
  31.         'phone' => array(
  32.             'rule'      => 'notEmpty',
  33.             'required'  => true,
  34.             'message'   => 'Please fill phone.'
  35.         ),
  36.         'roles' => array(
  37.             'rule'      => 'notEmpty',
  38.             'required'  => true,
  39.             'message'   => 'Please fill one role atleast.'
  40.         ),
  41.         'password' => array(
  42.             'rule'      => 'notEmpty',
  43.             'required'  => true,
  44.             'message'   => 'Please fill password.'
  45.         )
  46.     );
  47. }
  48.  
  49.  
  50. View File Code:
  51. <?php
  52.     /** registration form **/
  53.     echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'register'),'id' => 'registeration', 'class' => 'register', 'novalidate' => true));
  54.     echo $this->Form->input('User.fname', array('label' => 'First Name:', 'id' => 'fname'));
  55.     echo $this->Form->input('User.lname', array('label' => 'Last Name:'));
  56.     echo $this->Form->input('User.uname', array('label' => 'User Name:', 'id' => 'uname'));
  57.     echo $this->Form->input('User.email', array('label' => 'Email address:', 'id' => 'email'));
  58.     echo $this->Form->input('User.phone', array('label' => 'Phone:', 'id' => 'phone'));
  59.     echo $this->Form->input('User.address', array('label' => 'Address:'));
  60.     echo $this->Form->input('User.roles', array(
  61.                                 'type'          =>      'radio',
  62.                                 'options'       =>      array(1 => 'Customer', 2 => 'Vendor'), 'id' => 'roles'
  63.                                 ));
  64.     echo $this->Form->input('User.password', array('label' => 'Password:', 'id' => 'password'));      
  65.     echo $this->Form->input('User.cpassword', array('label' => 'Confirm Password:','type' => 'password', 'id' => 'cpassword'));
  66.     echo $this->Form->end('Save');
  67. ?>
  68.  
  69.  
  70. Controller file is:
  71. <?php
  72. App::uses('AppController', 'Controller');
  73.  
  74. class UsersController extends AppController {
  75.  
  76. /**
  77.  * This controller does not use a model
  78.  *
  79.  * @var array
  80.  */
  81.     public $uses = array('User');
  82.  
  83. /**
  84.  * Displays a view
  85.  *
  86.  * @return void
  87.  * @throws NotFoundException When the view file could not be found
  88.  *  or MissingViewException in debug mode.
  89.  */
  90.     public function index() {
  91.        
  92.     }
  93.    
  94.     public function login() {
  95.         //$this->layout = 'feedback';
  96.     }
  97.    
  98.     public function register() {
  99.                
  100.                 if($this->request->is('post')) {
  101.                        
  102.                         if($this->User->save( $this->request->data))
  103.                         {      
  104.                                 pr($this->request->data);
  105.                                 die('save');
  106.                         } else {
  107.                                 die('could not save');
  108.                         }
  109.                 }
  110.         }
  111.    
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement