Slideshow Image Upload

edited May 2013 in Modules
Hi
I have created a table to hold a list of images to be used in a slideshow/gallery.
My table simply needs a single field for the image.
I want to use a single image upload field for each image, not the asset manager.

If i call my field "image" i get the auto generated upload/select form but would rather just have a single choose file field.

I have used the form_fields method to change the field type to file but it doesn't seem to work as needed so I have changed my field name on the table to photo.

I can set the field type to file to get the choose file button and thats OK.

How can I use validation to check a file has been selected for upload?

I think it needs to be in a hook but can you explain which hook I need to use and return an error message that a file needs to be selected.

Many thanks.

Comments

  • edited 4:22AM
    If you are using the 1.0 beta, you'll need to use the parameter "ignore_representative" if you field name is "image". You can add validation in your on_after_post hook with something like the following (haven't tested it out):
    function on_after_post($values){ if (isset($this->upload_data['image'])) { $upload_path =(isset($this->upload_data['image']['full_path'])) ? $this->upload_data['image']['full_path'] : ''; if (!empty($upload_path) AND !file_exists($upload_path)) { $this->add_error('Error uploading file'); } } return $values; }
  • edited 4:22AM
    Many thanks ignore_representative was just what I needed.
Sign In or Register to comment.