Cakephp 3 dynamic validation error messages

Asked at 2017-01-11 21:24:42Z
  • 5 Subscribers
  • 114 Views
1

I'm validating file uploads in my form and i want to know if it's possible to display a dynamic message using information from the form.

This is my validation model:

public function validationDefault(\Cake\Validation\Validator $validator) {

    $validator
      ->allowEmpty('file')
      ->add('file', array(
        'extension'=>array(
          'rule' => ['extension', ['jpeg', 'png', 'jpg']],
          'message' => '[[fileName]] has no valid extension.'          
        ),
        'fileSize' => array(
          'rule' => array('fileSize', '<=', '100K'),
          'message' => '[[fileName]] exceed 100K.'),
        )
      ));

    return $validator;
}

I would like to replace the message to show for example: 'document.docx has no valid extension.'

I've read that this can be done with a custom validation, but i'm using proper cakephp validation not custom.

is there a way to do it or it can only be donde with a custom validation??


0 answers in total

Answer this questsion