Getting some variables from the url -...

User 2903705 Photo


Registered User
7 posts

Hi everyone,

I would like to populate fews text inputs in the form with variables coming from the url of the parent page (the page on which the form is embbed ; all on the same domain with manual export)

I search on the forum and found an example of javascript code made by Krysten :
https://www.coffeecup.com/forums/web-form-builder/prefill-based-on-url/

But my skill in javascript are very poor and after hours I’m not able to make it works...
Does someone could help with this code or by making a script that will automaticaly grab all the variables from the url and populate the corresponding item names on the form ?

Example : I have 3 variables on the url of the parent page : «v1,  v2 and v3 and I would like that in the form, the text field named « v1 » get the input of the variable v1 from the url, « v2 » get V2 variable…

Cheers
Emmanuel
User 187934 Photo


Senior Advisor
20,181 posts

Hi Emmanuel,
Are you publishing to your own host or S-Drive?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2903705 Photo


Registered User
7 posts

Hi Eric,
I'm publishing on my own host.
Thanks

User 187934 Photo


Senior Advisor
20,181 posts

Are you using an iframe to embed your form in your page?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2903705 Photo


Registered User
7 posts

Yes. I put the javascript code that WBF produces. So it's in iframe.
User 187934 Photo


Senior Advisor
20,181 posts

What I would do is remove the script surrounding the iframe. Then just a bit of adjustment to it to pass the url variables.
<iframe height="358" style="border:none; background:transparent; overflow:hidden; width:100%;"
id="fb_iframe" src="myformname/myformname.html?var1=one&var2=two">

Then you add the php $_GET to your forms input values.
<input name="answer1" id="item2_text_1" type="text" maxlength="254" placeholder=""
data-hint="" autocomplete="off" value="<?php echo $_GET['var1'];?>" />

<input name="answer2" id="item3_text_1" type="text" maxlength="254" placeholder=""
data-hint="" autocomplete="off" value="<?php echo $_GET['var2'];?>" />

You will need to set your server to parse php inside html. This is easiest through the .htaccess file by adding this line.
AddType application/x-httpd-php .php .html

I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2903705 Photo


Registered User
7 posts

Thank you Eric

when you say : "Then you add the php $_GET to your forms input values."
do you mean I have to edit the code of the form page that WBF produces, or do you add this code in WBF software (in that case where exactly) ?
User 187934 Photo


Senior Advisor
20,181 posts

You add the value="<?php echo $_GET['var1'];?>" to your form inputs after manual export. This setup can't be done within the Formbuilder or for S-Drive.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 2903705 Photo


Registered User
7 posts

Hi
It works now :)
One important point : as the Iframe links to the myform.html, I thought we didn't need the myform.php in the parent folder. But we actually need it to make the form working...
If it can help, here the code to grab one variable (var1) from the url :

<iframe height="358" style="border:none; background:transparent; overflow:hidden; width:100%;"
id="fb_iframe" src="myformname/myformname.html?var1=<?php echo $_GET['var1'];?>">


Thanks you for your help Eric.


Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.