Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Custom validation error message with ORM
  • Is it possible to define custom validation error messages in the ORM $_properties array?
    class Model_User extends Orm\Model {

    protected static $_properties = array(
    'id',
    'name' => array(
    'data_type' => 'varchar',
    'validation' => array('required', 'min_length' => array(3), 'max_length' => array(50))
    ),
    'email' => array(
    'data_type' => 'varchar',
    'validation' => array('required', 'valid_email')
    ),
    'mobile' => array(
    'validation' => array('required', 'valid_mobile', 'unique' => array('users.mobile'))
    ),
    'pword' => array(
    'data_type' => 'varchar',
    'validation' => array('required', 'min_length' => array(6), 'max_length' => array(20))
    ),
    'pin' => array(
    'data_type' => 'tinyint'
    ),
    'sms_id' => array(
    'data_type' => 'integer'
    ),
    'verified' => array(
    'data_type' => 'tinyint',
    'validation' => array('required'),
    'default' => 0
    ),
    'lastlogin',
    'createdon',
    'auth_token',
    'auth_token_expires' => array('default' => 0)
    );

    protected static $_observers = array(
    'Orm\\Observer_Validation',
    'Orm\\Observer_Typing'
    );

    }
    In the case of the above Model_User a value of "me" for name will result in an error message of "The field name has to contain at least 3 characters." I would like to override the error message in this case but not for other uses of "min_length"

    TIA

    Nick
  • No, that is not possible.

    Validation messages are defined per rule, not per field. The only way to do this is to define a custom rule.

Howdy, Stranger!

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

In this Discussion