0

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?

1 Answer 1

6

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').

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.