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??

Community
  • 1
  • 1
hug0
  • 511
  • 3
  • 17
  • I've tried this before and it's not easy. You need to manipulate the validator from inside the callback or something like that. Maybe it has been made more easy to do this now. – floriank Jan 11 '17 at 22:56

0 Answers0