Okay
  Public Ticket #2177297
Image upload on Front-end submit
Closed

Comments

  • senzoi started the conversation

    Hello,

    Always some questions... :-) i just see on your demo page for the frontend submit form, a button dedicated to upload image. but this button appear only for users not logged!? for user logged in, the media is shown!

    How to only have the upload image actif?

    I see on class.builder-elements, the function get_image_content. But i don't want to modify this core function.

    regards

  •  877
    Zhivko replied

    Go to your theme functions.php file and add following filter:

    add_filter('stec_builder_front_elements', function($elements) {
        ob_start();
        ?>
        <button type='button' class='stec-builder-element-content-button-style stec-builder-submission-add-image'>
            <i class="fas fa-plus"></i>
            <span><?php esc_html_e('Image', 'stec'); ?></span>
        </button>
        <span class="stec-builder-submission-add-image-src stec-builder-element-content-p-style"></span>
        <?php
        $elements['image'] = array(
            '<div {{params}}><input class="stec-builder-hide-upload" name="stec_public_file_image" type="file" accept="image/png, image/jpeg"/>' . ob_get_clean() . '</div>',
        );     return $elements;
    });

    This will show the upload image button at all times.


    However, you will have to modify the core code because  there is check in place if the user is logged-in it will only look for media images and will not check for upload files.


    Open file:

    stachethemes_event_calendar\assets\php\class.submit-event.php

    on line 154 starts this code:

            if (is_user_logged_in()) {
                if (Admin_Helper::isset_post('images')) {
                    $event->set_images(Admin_Helper::post('images', array(), FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY));
                }
            } else {
                if (isset($_FILES['stec_public_file_image'])) {
                    $image_id = self::image_file_upload($_FILES['stec_public_file_image']);                 if (filter_var($image_id, FILTER_VALIDATE_INT)) {
                        $event->set_images(array($image_id));
                    }
                }
            }

    Replace it with:

    if (isset($_FILES['stec_public_file_image'])) {
        $image_id = self::image_file_upload($_FILES['stec_public_file_image']);
        if (filter_var($image_id, FILTER_VALIDATE_INT)) {
            $event->set_images(array($image_id));
        }
    } elseif (is_user_logged_in() && Admin_Helper::isset_post('images')) {
        $event->set_images(Admin_Helper::post('images', array(), FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY));
    }
    

    I'll make this change in the next version as well so you won't have to do it again.


    Stachethemes Developer

  • senzoi replied

    It is good, thank you very much

  • senzoi replied

    In fact it is not so good, because the image is not uploaded!! And also are not showing??

  • senzoi replied

    No, sorry it was a mystake from i ;-)