Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
validation question
  • Hi guys, I am pretty new to FuelPHP. I have a user model (orm with validation rules).
    I have 2 pages: 1. Profile page to update user info (password not required, but can be changed) THIS WORKS.
    2. Create a new user page (all info is required just like profile page, but requires a password).
    Is there a way to change a model property (at least the validation rule)? Thanks
    These are the properties I use in my Model_User:
    class Model_User extends Orm\Model
    {
    
     /**
      * Table name
      *
      * @var  string
      */
     protected static $_table_name = 'users';
    
     /**
      * Primary key
      *
      * @var  array
      */
     protected static $_primary_key = array('id');
    
     /**
      * Properties
      *
      * @var  array
      */
     protected static $_properties = array(
      'id'             => array('data_type' => 'int'),
      'username'       => array('data_type' => 'varchar', 'validation' => array('required', 'valid_email', 'min_length' => array(3)), 'label' => 'label.username_or_email'),
      'password'       => array('data_type' => 'varchar', 'validation' => array('min_length' => array(3), 'match_field' => array('password2')), 'label' => 'label.new_password'),
      'password2'      => array('data_type' => 'varchar', 'label' => 'label.repeat_new_password'),
      'group'          => array('data_type' => 'int'),
      'email'          => array('data_type' => 'varchar', 'label' => 'email'),
      'firstname'      => array('data_type' => 'varchar', 'validation' => array('required'), 'label' => 'label.firstname'),
      'lastname'       => array('data_type' => 'varchar', 'validation' => array('required'), 'label' => 'label.lastname'),
      'last_login'     => array('data_type' => 'int', 'default' => 0),
      'login_hash'     => array('data_type' => 'varchar', 'default' => ''),
      'profile_fields' => array('data_type' => 'serialize', 'default' => ''),
      'reset_hash'     => array('data_type' => 'varchar', 'default' => ''),
      'created_at'     => array('data_type' => 'time_unix'),
      'updated_at'     => array('data_type' => 'time_unix'),
     );
    
     /**
      * Used observers
      *
      * @var  array
      */
     protected static $_observers = array(
      'Orm\\Observer_Validation' => array(
       'events' => array('before_save'),
      ),
      'Orm\\Observer_Typing' => array(
       'events' => array('before_save', 'after_save', 'after_load'),
      ),
      'Orm\\Observer_CreatedAt' => array(
       'events' => array('before_insert')
      ),
            'Orm\\Observer_UpdatedAt' => array(
             'events' => array('before_save')
            ),
            'Observer_Password' => array(
             'events' => array('before_save'),
             'fields' => 'password'
            ),
     );
    }
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!