Upload files

This topic contains 4 replies, has 2 voices, and was last updated by  Stephen Harris 1 month, 2 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36367

    Hi Stephen,

    I would like to authorize the sending of pdf files or images when submitting an event.
    I saw that the form proposes a “event thumbnail” field, and I was wondering if it would be possible to use this field as a model to add the possibility of uploading a file?
    The uploaded file should be available for consultation or downloading on the front end by authorized persons who consult or modify the event.

    Kind regards,

    Olivier

    Philippe Arsane
    #36444

    Hello Stephen,
    No answers?
    Best regards,
    Olivier

    Philippe Arsane
    #36470

    HI Olivier,

    Apologies, at this point the plug-in doesn’t support uploads other than featured images. I can look into adding this in the future, but I can’t give an a date when these would be developed because of other features being worked on.

    Stephen Harris
    #36801

    Hello Stephen,
    At the request of a customer, we are developing a file upload field for the event submission form…
    We have therefore added a File Type field to the front end form, respecting your development structure.
    Can you tell me which files and functions are used for validating and recording the form data?
    We will send you the result of our work so that you can eventually integrate it into a future version of the plugin.
    Best regards,
    Olivier

    Philippe Arsane
    #36859

    So EO_Event_Form_Element_Event_Thumbnail does a lot of the validating, and looks in $_FILES arrays for details of the upload. You should probably base your class on that, and have is_valid() implement whatever logic you want in terms of restricting file types, size etc, and get_value() return information on the uploaded file.

    Assuming you’ve defined that class and added an instance to for the form object then you the plug-in will automatically invoke your validation logic (by calling is_valid(). You would just then need to handle the actual uploading of file.

    You can do that by hooking into eventorganiser_fes_submitted_event, and the calling get_value on your form element instance to get the details of the uploaded file.

    add_action( 'eventorganiser_fes_submitted_event', function($event_id, $event, $form){
         $your_field = $form->get_element('YOUR FIELD ID');
    
         $upload = $your_field->get_value();
    
         //move file into appropriate location using wp_handle_upload
    }, 10, 3);
    

    For thumbnails, the plug-in uses eo_handle_thumbnail_attachment() – using values returned by get_value(). This is just a wrapper for wp_handle_upload() to move the file to the uploads directory and then wp_insert_attachment to attach the file to the event. You may want to do something similar,

    Stephen Harris
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.