Prestashop: How I can add a variable (ex: $product_reference) as a prepopulated field in my form?

  • ariom
    Asked on June 11, 2015 at 8:01 AM

    Goodmorning all, 

    Is there a way to add the value of a variable (ex: $reference, $id_product, $produc_name or any other) as a precompiled field in my form depending on the product page i am coming from?

    I'm tryng to implement and embedd this form on a Prestashop 1.6.0.14, i can get all the variables i need but i don't know hou to make them to be filled in automactly on the right field.

    Can you pls give me a suggestion how to achieve this?

    Thanks in advance and best regards to you all.

    Mario

  • Carina
    Replied on June 11, 2015 at 12:07 PM

    I'm not very familiar with Prestashop but I think pre-populate app can help:

    http://prepopulate.jotform.io/ 

    In this case it is the same form but the form's link will be different, according to the product:

    https://shots.jotform.com/carina/HTML/prepopulate.html 

    Let us know if this is a solution for you.

  • ariom
    Replied on June 12, 2015 at 1:24 AM

    Thanks for your replay.

    i looked to what you suggested, but unfortunatly it is not the solution i'm looking for.

    i have to call a variable value {$product->reference|escape:'html':'UTF-8'} depending on the product page where i click the button to go to the form, and the right form field should be dinamically precompiled with that value.

    you can see here what i mean:

    http://www.navyonepal.com/navyonepal/it/lista-dei-viaggi-in-bhutan/22-viaggio-culturale-nel-regno-del-bhutan-classico.html

    there is a button  "RICHIEDI IL PROGRAMMA DETTAGLIATO PER QUESTO VIAGGIO" calling a cms page with the form iFrame

    Any help is welcome....

    Thanks in advance

    Mario

  • Ashwin JotForm Support
    Replied on June 12, 2015 at 6:40 AM

    Hello Mario,

    I did check the web page URL which you have shared but I am unable to find any button with text "RICHIEDI IL PROGRAMMA DETTAGLIATO PER QUESTO VIAGGIO".

    Can you please guide us where to find this button to be able to understand your requirement? You may also like to share a screenshot as well and we will take a look. The following guide should help you upload image in forum post:  http://www.jotform.com/answers/277033 

    I do have one another question as well. Do you mean to say that the PHP code "{$product->reference|escape:'html':'UTF-8'} " return the value which you need to prepopullate in your form field?

    We will wait for your response.

    Thank you!

  • ariom
    Replied on June 12, 2015 at 8:42 AM

    Really thanks for your replay,

    Here atached in screenshoot-1 you can see the button, just before the social icons, that call the cms page with the form Iframe from the product page, example from http://www.navyonepal.com/navyonepal/it/lista-dei-viaggi-in-bhutan/22-viaggio-culturale-nel-regno-del-bhutan-classico.html.

    In the second is the form Iframe with the field that should be prepolutated by the php variable"{$product->reference|escape:'html':'UTF-8'} " that should return the value that i need to pre-populate the field, depending on the product page i am, right as you say.

    I have no  way to insert the form but Iframe, cause any other is giving a lot of js conflicts...and i'm not a coder so it'svery difficult for me....

    Thanks for your time an your valuable help!

    Mario

    Prestashop: How I can add a variable (ex: $product reference) as a prepopulated field in my form? Image 1 Screenshot 20

  • ariom
    Replied on June 12, 2015 at 8:49 AM

    oops! i forgot screenshoot-2....:

    thank for helping

    MarioPrestashop: How I can add a variable (ex: $product reference) as a prepopulated field in my form? Image 1 Screenshot 20

  • Carina
    Replied on June 12, 2015 at 10:08 AM

    I will investigate further and will let you know as soon as I have more details.

    Let us know if we can assist you further.   

  • ariom
    Replied on June 12, 2015 at 12:20 PM

    Thank you so much for your time,

    at the moment i put the Iframe code on the product page so the button will just toogle the visibility of the form. this will make much more easy to get the current php variable{$product->reference} value because it is on-scope.

    Then i think the html for the input field should be as follow:

    <div id="cid_28" class="form-input jf-required">
    <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_28" name="q28_reference" size="20" value="{$product->reference|escape:'html':'UTF-8'}" />
     </div>
     </li>

    but i can't modify the form cause it is an iframe, and i'm not a coder so become very difficult for me to implement it inside prestashop also cause there are a lot of js conflicts, () already try to call jQuery.noConflict function but it is working only for some, not for all...)

    Any more help will be much appreciate...

    Thank you all,

    Mario

  • Carina
    Replied on June 12, 2015 at 1:46 PM

    Hello Mario

    If that is the case you can edit the form's source code and add it to a page and then add that page as an iFrame.

    You can see here the example:

    form source code page:

    https://shots.jotform.com/carina/HTML/Title%20Me.html 

    page embed as iFrame:

    https://shots.jotform.com/carina/HTML/iframe56.html 

    You can also see our guide on PHP forms:

    https://www.jotform.com/help/237-PHP-Forms-Explained 

    Let us know if that worked.

     

  • ariom
    Replied on June 13, 2015 at 6:33 AM

    Hello,

    thanks for your effort and suggestion!

    I will take the time to check later in afternoon and i'll let you know....

    hope it will work in some ways

    Thanks a lot ... wish you a nice weekend!

    regards

    Mario

  • Welvin Support Team Lead
    Replied on June 13, 2015 at 5:20 PM

    Hi Mario,

    Can you also check this widget: http://widgets.jotform.com/widget/get_referrer ? If you are trying to get the page reference, this widget should do it.

    Thanks

  • ariom
    Replied on June 14, 2015 at 1:20 AM

    Thanks for your suggestion.

    I tried it, but unfortunatly it is not working for me, it is working if i try it with example widget form preview from the jotform panel, then i insert widget in my form, go to my site, open iframe form and send it, no referrer at all in the mail received...

    Any other suggestion is welcome...

    Thank you all.

    Mario

     

  • Welvin Support Team Lead
    Replied on June 14, 2015 at 9:52 AM

    Hi Mario,

    Actually, your method of appending the PHP Snippet in the iFrame embed codes should work. You have the following:

    http://form.jotformeu.com/form/51612259464355?reference=<?php echo $product->reference ?> 

    However, you saved the page as an .HTML. PHP echo function can't work inside an HTML page. You should save the page as .PHP. 

    http://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php?rq=1

    Please get back to us if you need further assistance.

    Thanks

  • ariom
    Replied on June 14, 2015 at 12:00 PM

    Hi Welvin, thank you for helping.

    ... prestashop uses smarty as template engine so, looking at the page source, you see the page as .html, but the real page where i insert the iFrame embed codes with the php snippets it is a smarty template (.tpl) ... because of that it is maybe not working.

    Maybe I should then make a .php page on my root directory and call that .php page as iFrame in the .tpl, but in that case i'm going to have a lot of trouble with .js conflicts, i tried before with no result so i preferred just embed full form files as iFrame.

    I know i'm very close to solution, but i'm sorry, i've so little knowledge in coding, very basic, and i see this is going so far...

    I'm really gratefull for your help and support, will try again and see if i can get to the point.

    Best regards

    Mario

     

     

  • Welvin Support Team Lead
    Replied on June 14, 2015 at 1:44 PM

    Hi Mario,

    I searched for a possible solution about this. What I've found is that you shouldn't use PHP echo. You should just do it like this:

    http://form.jotformeu.com/form/51612259464355?reference={$product->reference}

    Or this:

    http://form.jotformeu.com/form/51612259464355?reference={$product.reference}

    And then make sure that the above snippets are present in your .TPL file. Please try it and let us know if that works. If not, I would suggest contacting Prestashop Support and ask them if what's the best way to append the info in an external form like Jotform.

    Thanks

  • ariom
    Replied on June 14, 2015 at 4:49 PM

    WOW... IT'S WORKING...

    http://form.jotformeu.com/form/51612259464355?reference={$product->reference}

    was the solution...perfect as i need... so easy and simple that i could not see, i look far and i have it under my eyes!

    i have to thank you all for the patience to assist me ... you are really great!!!

    Mario

     

  • ariom
    Replied on July 18, 2015 at 1:12 PM

    I'm back again asking if somebody can help on the same question ... cause i see an issue

    I try to explain:

    i can now get the variable product reference for the first product i am on, but if i change page and open the iframe form, the reference of the previous product is there... no way, i have to manually delete it and reload the page to get the new page product reference...

    it makes me crazy...i've been looking for a solution searching and googling without any result...

    somebody can point me to the solution?

    thanks in advance

    mario

  • Welvin Support Team Lead
    Replied on July 18, 2015 at 2:47 PM

    Hi Mario,

    I can't seem to find a solution for this matter. The only workaround I can offer is to let your customer edit the product reference then advise them to change the value whenever they change the product or go into another product page. 

    Maybe, you should also ask Prestashop support about this matter to see if they can help.

    Thanks