Shaheer
Shaheer

Reputation: 2147

CakePHP validation error doesn't show up on file upload field

I have a file upload field in CakePHP which allows images to be uploaded.

All is fine. All I need to do is validate the field. I am using the solution from CakePHP – Uploaded File Validation in Models:

The function is working and returning the appropriate error. I am using the following code to generate the file upload field.

echo $form->label('Game Thumbnail');
echo $form->file('Game.game_thumbnail_url');

and following code to add the validation in the model

'game_thumbnail_url' => array(
    'valid_upload' => array (
      'rule' => array('validateUploadedFile', false),
       'message' => 'Please select a valid game thumbnail',
       'allowEmpty' => false
  )
),

But the error message doesn't show up, it works fine for other fields but not for this one.

How can this problem be fixed?

Upvotes: 0

Views: 924

Answers (1)

deceze
deceze

Reputation: 522016

If you're not using FormHelper::input, which outputs the field, label and error, you need to manually output the error as well using $form->error('Game.game_thumbnail_url').

Upvotes: 6

Related Questions