Jump to content

How to upload file from front-office to the server ?


Recommended Posts

Hello,

 

I have to develop a module for my internship but I'm stuck on a feature.

I have to allow a user (a customer of the site) to import a picture on the site so that the company can add this picture on its social networks. (everything must go through a module implemented by the 'WidgetInterface')

Searching in the prestashop code, I could find this form to put in the front-end .tpl file:

 <form method="post" action="" enctype="multipart/form-data" novalidate>

        <span class="js-file-name">{l s='No selected file' d='Shop.Forms.Help'}</span>
        <input class="file-input js-file-input" {if $field.required} required {/if} type="file" name="{$field.input_name}">
        <button class="btn btn-primary">{l s='Choose file' d='Shop.Theme.Actions'}</button>

        <div class="clearfix">
            <button class="btn btn-primary float-xs-right" type="submit" name="submit">{l s='Save Customization' d='Shop.Theme.Actions'}</button>
        </div>
    </form>

However, I have no idea how to get this file in my php file that manages the module. I try to retrieve this file through the Tools::isSubmit() method but I don't get anything at all...

 

    /**
         * Gestion du front-end
         */
        public function getWidgetVariables($hookName, array $configuration)
        {

            if (Tools::isSubmit('submitMessage')) {
                print_r("We recovered data");
            }

            

            return array(
                'productss' => 'Test',
            );
        }

I would be very grateful if you could unblock me ! Thanks you very much !

 

William

Link to comment
Share on other sites

Hello, @Oversky

Where you want to put this. In home page or in product page. I suggest you to hook your content in any hook and in that hook you can show your template. When submit button press you can handle the post back data in the same hook.

 

If you give more details picture ,I will try to help you.

 

Thank you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...