If you enjoyed this video don't forget to the like it and subscribe! Then check out this playlist about doing nearly everything with Contact Form 7: ua-cam.com/video/wy70WGCjMY4/v-deo.html
Thank you very much. Just confirming this works in the dropdown too. I see some comments saying this only works in the textfields but it woked for me in the select tag too.
WordPress and many themes are notorious for over doing script calls in the header. For this script, I suggest to insert it into the content of the page itself a shown in the video. Question: If we want the URL to include a page anchor (#anchor), how can that work so the page scrolls and inserts the parameter? Currently, your script won't work with a hash tag anchor to the URL. - would be good to know. Also for others to know, since this video did not cover this part, which I think was important. If the text you want has several words to it, you cannot use any symbols, else the script will insert those symbols/characters as well. For example, I want to insert a pre-made subject title in to the Subject Field box, such as "Making a comment". I cannot write that like this, Making-a-comment, or like this Making+a+comment, which is how some websites suggest. I have to write it like it shows in the subject field box : Making a comment So after the "=" sign, write the words as normal, Making a comment and it will appear the same way in the field box.
Can we do the reverse ?. , meaning being able to change the redirect to link based on what the user inputs on one of the form fields ?? By adding the parameter inside the url ,based on what the variable the user types in the form
Hi there Bjorn, similar questions have been asked here, but they're either not answered or not what I'd like to achieve...! How can I please, pass input fields from a booking widget, (dates, drop down input), to another page where it has the full form? Basically, once the user fills out the specific fields above, to not have to fill them out again once re-directed to the full form..?! Thank you for any ideas please!!!!!
You kinda sound like Jim Halpert. Also, thanks for the information! The only thing that was weird for me was that the box fills in as undefined if you don't have the params. I fixed it with a simple if statement though.
Don't use a hyphen in the variable name! I do not know JavaScript and tried this with a "-" in the variable name.. took that out and wow, this is just what I needed.. Thank You!!
Hello, there is anyway to apply this for a dropdown box. I just wanted to bring an option from other page and show this option preselected on my dropdown. COuld you help me with please?
Hello, thanks for the video! its great. Could you also tell me how I can get the values from contact form 7 and prefill it in another page by adding the parameter in the URL of the new page?
Hi Madhavi, you can do that with JS or PHP. I'll don't have the code for that yet. I bet if you Google it you'll find something on Stack Overflow to could be helpful. I hope that helps, let me know if you have any further questions. Thanks for watching!
Just looking further, I notice that CF7 doesn't add the id to the tag, but rather a "grandparent" tag. Perhaps this is why it's not working? Welcome your suggestion here, thanks again!
Hy can it be used for setting drop down menu..because for rest of the fields it is working fine..but drop down field is not being set although value is coming from URL.Can you help me with that?
Thanks a bunch for the Tutorial. I'll appreciate if you can post a video or just explain how tog et the parameter into the url. Personally i've been trying to implement something like this, in my case, the user clicks a picture and the the picture opens a link to a contact page where the name of the picture is already autofilled. Getting the name of the picture into the URL is now the main challenge. I'll appreciate if you can show me how or point me to a tutorial. Thanks
Hi Babatunde, How many images are you doing this for? If it's only for a few images you could do put the parameter in manually. You create the link around the image. Then just add ?parameter=variable at the end of the link for the image. Replacing parameter and variable with what you need in there. If you have lots and lots of images to do this for you could do it programmatically using Javascript. I hope that helps and thanks for watching!
@@wplearninglab Hi, I just add ?parameter=variable at the end of my button links or image links, but then link doesn't work anymore. (for example, I added ?country=USA). Do you have a solution, or could you make a video on adding parameters to url ? Thanks
Hiya, how can I add a specific parameter for every page I have? Or is it possible to achieve the same result using only url path instead of a parameter?
Hi there! thanks for this awesome tutorial. I want to ask you a question that everything is working fine on my end but i want that when someone already chose fields from another page and those fields were auto generated on contact form 7 than i do not want users to change those fields on contact form 7....that is once the fields were added to the contact form 7 through url parameters than user won't be ale to change them...how can i do it ?
Hi Farhan, I think I understand what you want to do. I think you want to have fields autofilled from URL parameters and if a field is autofilled in that way you want that field to be uneditable. What you need is to make to field 'read only'. We this page for more info: html.com/attributes/input-disabled/ You'll need to had an 'if' statement to the JS to detect if a filed has a value. If it has a value then you need to add the readonly attribute to it. You should be able to do this using the 'setAttribute' method in Javascript. Here's a page about it:. www.w3schools.com/jsref/met_element_setattribute.asp I hope that helps, let me know if you have any further questions. Thanks for watching!
@@wplearninglab Thank you so much for your response and i will try my best to understand it but i am non technical user so it is very hard for me to add and modify the code so kindly make a video on this if you can for ever non technical user. Thank you
Had to remove this to get it working if one of the parameters was not in the URL if (VARIABLE != null) - and replace with this if( typeof variable === 'undefined' || variable === null ) I guess it was looking for null and was not seeing it read as undefined Ps..How would you code this if you wanted to pass say a persons name outside the form fields at the top of the page like HI, {{first_name}} blah blah ?
Hi Scott, Great addition to the script. I'll update the code on the website. This tutorial ( ua-cam.com/video/YL6C0NzRsgI/v-deo.html ) takes the name parameter from the URL and prints it onto the page. It gets the first name from Mailchimp, you can skip that part and just use the rest of the tutorial. I hope that helps :) Let me know if you have any further questions. Thanks for watching!
How do i button click and get URL value to pre-fill in contact form 7. i want someone to click a apply now button and it redirects them to form page with prefilled name of course to apply for
Hi Charles, Ignore my reply to your other comment, this one clears it up. You should be able to get the URL of the previous page (the one that the "apply now" button was clicked on) by using this: var referrer = document.referrer; Then you use the variable referrer in the JS code from this video to pre-fill the form. You can find more info on document.referrer here: developer.mozilla.org/en-US/docs/Web/API/Document/referrer I hope that helps :) Let me know if you have any further questions. Thanks for watching!
There are two ways to autofill forms with WordPress: JavaScript or PHP. Which on you choose depends on where the data is coming from. If the user is inputting data that you want to be autofilled somewhere else you would use custom JavaScript. If the data is coming from the database then you would use PHP. That said, you can almost always build a script that will autofill one field based on another. To help you with your situation I would need more details.
Hello, I've followed few of your video and that's great, your work is great! By the way, with this one I have a problem... If I'm following your indications as in this video, it works. "Dirty way" as you said. Means the script is in my contact form. If I'm following a clean method, this one (wplearninglab.com/add-javascript-specific-wordpress-pages/), it doesn't work. Firebug is telling me "GetElementById(...) is null" and if I understand well, it's because the script is loaded BEFORE the html element is generated so the script doesn't find it... P.S. And I didn't find the way to make it works with radio/checkbox... :(
If you already know what the coupon is going to be you can program it right into the form. As long as you can edit the form. Just add this to the coupon input field: value="coupon-code-here" That should put the coupon into the field. The use can edit it if they want, but they probably wouldn't. I hope that helps and thanks for watching!
Hi also - I found a couple of issues with your website. Check the footer. Also your Contact page is empty (tried to reach ou there to let you know about issues). All the best.
I tried this a few hours now up till using exactly the same names and instances as you did on a completely new post. I just cannot get it to work... no idea what is wrong =/
And also make sure you empty your cache in case you're using a caching plugin or empty the cache in Cloudflare, if you use Cloudflare and use CTRL+F5 to reload your page without using the browser cache.
I made a contact form with this feature and it doesn't seem to work on mobile. Everything is fine, it's just the submit button that shows a spinning wheel on mobile and doesn't submit. On desktop it works fine.
Hi Charles, If I understand correctly, you want the current page URL pre-filled into a CF7 form field on the same page when a button is clicked. Is that correct?
Hi Shawn, Thanks for letting me know. The code is there now: wplearninglab.com/contact-form-7-get-value-from-url/ Let me know if you run into any problems or having any further questions!
Hi, Thank you for the video, i tried exactly how you explained. Edited contact form ID attribute, added script the page, changed the Variable, Parameter and Input. The form is loading fine when called with original URL, but after adding the parameter value and click on Enter, page is showing up 404 error. Can you please suggest what could go wrong, any URL settings etc. Thanks advance for the help
Hi Satya, it sounds like an error when you're testing the url parameters. Make sure they are structured like this: yourdomain.com/page-slug?fname=Satya&email=email@email.com The important parts are the ?, the = and the &. Having those in the wrong places will cause a 404. Let me know how it goes!
Hi, the problem is i have, used the same name for variable also and in CF7 form column name also. That's why 404 error. Now it is working fine. thank you for your swift response. I just have one more question, how to pass an ID value as parameter, which will look into some reference and fetch the other field and fill the form fields. Can you please help how to achieve that
HI, Thank you for you reply, Right now My ID value is in Azure SQL Database. It is a database table actually. If we pass ID value as parameter in URL, the URL should refer the table and fetch the Name and Title columns and fill up the Form in wordpress. That is the need. Instead we can also save the table in CSV format, so that we can host the file in FTP and refer the same. Can you please guide me how to achieve that using CF7 and javascript. Thank you very much in advance.
I'm using CF7 and Mautic, and I have a problem that when there is a space in a Name (ex. John Smith), on the form It will input as "John+Smith", so It doesn't read that there is as space in between. Do you know how to fix it?
hi, i tried the same thing!! and also did console log it is showing undefined. it is mainly because i am not able to understand the type of parameter! can someone help me out over here
Hello Sir, This is a good tutorial but can you please guide me further i want to do something like that i have two steps Contact Form 7 form and i put two address fields on first step and i also put these fields on second step and i want if someone come to my website and fill out these fields on first step and click on next so on second step i also put two address fields but i want when the user come on this step so these address fields are auto filled by grabbing the data from first step about which i told you before. So please response me if you have any idea about that. Thanks..
Hi Amanji, You can make actions happen on the site without submitting and without refreshing a page using AJAX, which JavaScript. Can you give more details on what you're trying to achieve?
Hi, Thank you for the script, everything work really fine except the date field... please let me know the syntaxe of the URL parameter ie : &date=01/01/2019 this syntaxe is not working cause the slash is considered like the rest of the URL... please let me know how to autofill the date field witch is a calendar picker and only work with manuel fill... thanks !
If you enjoyed this video don't forget to the like it and subscribe! Then check out this playlist about doing nearly everything with Contact Form 7: ua-cam.com/video/wy70WGCjMY4/v-deo.html
Thank you very much. Just confirming this works in the dropdown too. I see some comments saying this only works in the textfields but it woked for me in the select tag too.
This video is amazing - WORKED PREFECTLY - thank you!
WordPress and many themes are notorious for over doing script calls in the header. For this script, I suggest to insert it into the content of the page itself a shown in the video.
Question: If we want the URL to include a page anchor (#anchor), how can that work so the page scrolls and inserts the parameter?
Currently, your script won't work with a hash tag anchor to the URL. - would be good to know.
Also for others to know, since this video did not cover this part, which I think was important. If the text you want has several words to it, you cannot use any symbols, else the script will insert those symbols/characters as well.
For example, I want to insert a pre-made subject title in to the Subject Field box, such as "Making a comment".
I cannot write that like this, Making-a-comment, or like this Making+a+comment, which is how some websites suggest.
I have to write it like it shows in the subject field box : Making a comment
So after the "=" sign, write the words as normal, Making a comment and it will appear the same way in the field box.
Thank you Boss You have saved my life..
I’m happy to help Faiza, thanks for watching!
i want user re-driected to form pre-filled in another page that has the CF7 form when button is clicked
Can we do the reverse ?. , meaning being able to change the redirect to link based on what the user inputs on one of the form fields ?? By adding the parameter inside the url ,based on what the variable the user types in the form
This is work thanks sir 😁👍👍
Hi there Bjorn, similar questions have been asked here, but they're either not answered or not what I'd like to achieve...! How can I please, pass input fields from a booking widget, (dates, drop down input), to another page where it has the full form? Basically, once the user fills out the specific fields above, to not have to fill them out again once re-directed to the full form..?! Thank you for any ideas please!!!!!
This was incredibly helpful.
Thanks Joseph and thanks for watching!
You kinda sound like Jim Halpert. Also, thanks for the information! The only thing that was weird for me was that the box fills in as undefined if you don't have the params. I fixed it with a simple if statement though.
I have the same problem and I don't know how to fix it ..
you can help? Thank you!
Works pretty perfect! Thanks!
You’re welcome Martin, thanks for watching!
Don't use a hyphen in the variable name! I do not know JavaScript and tried this with a "-" in the variable name.. took that out and wow, this is just what I needed.. Thank You!!
Hi Barry,
Good call, I messed that up. Sorry!
I'm updating the blog post soon.
Hello, there is anyway to apply this for a dropdown box. I just wanted to bring an option from other page and show this option preselected on my dropdown. COuld you help me with please?
Hello, thanks for the video! its great. Could you also tell me how I can get the values from contact form 7 and prefill it in another page by adding the parameter in the URL of the new page?
Hi Madhavi, you can do that with JS or PHP. I'll don't have the code for that yet. I bet if you Google it you'll find something on Stack Overflow to could be helpful. I hope that helps, let me know if you have any further questions. Thanks for watching!
Have You found a solution to your question yet? I'm currently trying to do the same thing.
Hey Guys, Me too in search of same do anyone got the solution for it? If yes than please help me out.
Thank You In Advance 🙏🏻
Very informative indeed.But can you tell the code for for field to take up values from google sheets.
Saviour thanks man!!
Hello, Thanks for the video.
But How do you send a parameter through an url from fields in a form? Do you have any tips?
Will this work on caldera forms ??
Thank you so much for this video, I was trying very hard to autofill fields work.
You're welcome Shital, did you get the autofill working with the help of this tutorial?
Thank you for this great tutorial, all working great.
Thank you, does it works with radio elements?
Thank you so much for the tutorial.
How would you do the same to prepopulate the Registration form of woocommerce? I can’t find where to insert the js
Hi I am having an issue where the variable enters into the field, but quickly disappears. Any idea what's going on?
Hi, thank you for very helpful tutorial, but when its prefilled its going disappear after page loading finished, how can I solve that , thank you!
Hi thanks for sharing this! Could you explain how to pre-check a checkbox? Thanks so much.
Just looking further, I notice that CF7 doesn't add the id to the tag, but rather a "grandparent" tag. Perhaps this is why it's not working? Welcome your suggestion here, thanks again!
great tutorial thats
Thanks and thanks for watching!
Hy can it be used for setting drop down menu..because for rest of the fields it is working fine..but drop down field is not being set although value is coming from URL.Can you help me with that?
I have make the script work so thank you so much. The only issue is that its showing the field value on page load and going off after that.
How do you get values from wp database? Nice video.
Hi mate, can i autofill Fileds with value from a file php or xml on my website?
Is there an update to the script? It did work a few months ago but I cannot make it work now.
Is it possible, if plugin can do that for Divi (elegant themes)
Thanks a bunch for the Tutorial. I'll appreciate if you can post a video or just explain how tog et the parameter into the url. Personally i've been trying to implement something like this, in my case, the user clicks a picture and the the picture opens a link to a contact page where the name of the picture is already autofilled. Getting the name of the picture into the URL is now the main challenge. I'll appreciate if you can show me how or point me to a tutorial. Thanks
Hi Babatunde,
How many images are you doing this for? If it's only for a few images you could do put the parameter in manually.
You create the link around the image. Then just add ?parameter=variable at the end of the link for the image.
Replacing parameter and variable with what you need in there.
If you have lots and lots of images to do this for you could do it programmatically using Javascript.
I hope that helps and thanks for watching!
@@wplearninglab Hi, I just add ?parameter=variable at the end of my button links or image links, but then link doesn't work anymore. (for example, I added ?country=USA). Do you have a solution, or could you make a video on adding parameters to url ? Thanks
Hiya, how can I add a specific parameter for every page I have? Or is it possible to achieve the same result using only url path instead of a parameter?
Hi there! thanks for this awesome tutorial. I want to ask you a question that everything is working fine on my end but i want that when someone already chose fields from another page and those fields were auto generated on contact form 7 than i do not want users to change those fields on contact form 7....that is once the fields were added to the contact form 7 through url parameters than user won't be ale to change them...how can i do it ?
Hi Farhan,
I think I understand what you want to do. I think you want to have fields autofilled from URL parameters and if a field is autofilled in that way you want that field to be uneditable.
What you need is to make to field 'read only'. We this page for more info: html.com/attributes/input-disabled/
You'll need to had an 'if' statement to the JS to detect if a filed has a value. If it has a value then you need to add the readonly attribute to it. You should be able to do this using the 'setAttribute' method in Javascript. Here's a page about it:. www.w3schools.com/jsref/met_element_setattribute.asp
I hope that helps, let me know if you have any further questions. Thanks for watching!
@@wplearninglab Thank you so much for your response and i will try my best to understand it but i am non technical user so it is very hard for me to add and modify the code so kindly make a video on this if you can for ever non technical user. Thank you
Bjorn you are a good block
haha @ "block" Vern, I love it. I'm glad you didn't edit it this time :)
Lol and thx for another great tutorial
Had to remove this to get it working if one of the parameters was not in the URL
if (VARIABLE != null) - and replace with this if( typeof variable === 'undefined' || variable === null )
I guess it was looking for null and was not seeing it read as undefined
Ps..How would you code this if you wanted to pass say a persons name outside the form fields at the top of the page like HI, {{first_name}} blah blah ?
Hi Scott,
Great addition to the script. I'll update the code on the website.
This tutorial ( ua-cam.com/video/YL6C0NzRsgI/v-deo.html ) takes the name parameter from the URL and prints it onto the page. It gets the first name from Mailchimp, you can skip that part and just use the rest of the tutorial.
I hope that helps :) Let me know if you have any further questions. Thanks for watching!
How do i button click and get URL value to pre-fill in contact form 7.
i want someone to click a apply now button and it redirects them to form page with prefilled name of course to apply for
Hi Charles,
Ignore my reply to your other comment, this one clears it up.
You should be able to get the URL of the previous page (the one that the "apply now" button was clicked on) by using this:
var referrer = document.referrer;
Then you use the variable referrer in the JS code from this video to pre-fill the form.
You can find more info on document.referrer here: developer.mozilla.org/en-US/docs/Web/API/Document/referrer
I hope that helps :) Let me know if you have any further questions. Thanks for watching!
hi there..can we autofill html form field elements to the containing api form
There are two ways to autofill forms with WordPress: JavaScript or PHP. Which on you choose depends on where the data is coming from.
If the user is inputting data that you want to be autofilled somewhere else you would use custom JavaScript. If the data is coming from the database then you would use PHP.
That said, you can almost always build a script that will autofill one field based on another. To help you with your situation I would need more details.
Hello,
I've followed few of your video and that's great, your work is great!
By the way, with this one I have a problem...
If I'm following your indications as in this video, it works.
"Dirty way" as you said. Means the script is in my contact form.
If I'm following a clean method, this one (wplearninglab.com/add-javascript-specific-wordpress-pages/), it doesn't work.
Firebug is telling me "GetElementById(...) is null" and if I understand well, it's because the script is loaded BEFORE the html element is generated so the script doesn't find it...
P.S. And I didn't find the way to make it works with radio/checkbox... :(
Thanks for sharing this. Can you please share the script for getting the entire url as well?
Hi! In arrays my square brackets [i] get escapted to [i] What can I do?
Is there anyway to do this easier with a product page and say a coupon code pre-filled into the box?
If you already know what the coupon is going to be you can program it right into the form. As long as you can edit the form.
Just add this to the coupon input field:
value="coupon-code-here"
That should put the coupon into the field. The use can edit it if they want, but they probably wouldn't.
I hope that helps and thanks for watching!
Thank you for the reply! I'll give it a shot and see how it works out! Big thumbs up and subbed!
Thanks for the sub, much appreciated! Let me know how it goes :)
When I put ?subj=example in my permalink url it becomes subj-example. How do I set manually a URL so that I can use it on a button from my homepage?
kindly make dropdown tutorial auotfill
Hi also - I found a couple of issues with your website. Check the footer. Also your Contact page is empty (tried to reach ou there to let you know about issues). All the best.
I tried this a few hours now up till using exactly the same names and instances as you did on a completely new post. I just cannot get it to work... no idea what is wrong =/
Hey Martin,
If you open the 'inspector' in your browser, are you seeing any errors in the 'console' tab?
And also make sure you empty your cache in case you're using a caching plugin or empty the cache in Cloudflare, if you use Cloudflare and use CTRL+F5 to reload your page without using the browser cache.
@@wplearninglab and this is in the form
[text* item id:urlitem placeholder "exempel: Kajak, handväska, sommarhus, drönare"]
I made a contact form with this feature and it doesn't seem to work on mobile. Everything is fine, it's just the submit button that shows a spinning wheel on mobile and doesn't submit. On desktop it works fine.
Help..How do i button click and get URL value to pre-fill in contact form 7
Hi Charles,
If I understand correctly, you want the current page URL pre-filled into a CF7 form field on the same page when a button is clicked. Is that correct?
@@wplearninglab i want it pre-filled in another page that has the CF7 form when button is clicked
how to send one wordpress form value to next wordpress form (textbox to textbox print) please help me
Can you update the blog page because the code is now missing?
Hi Shawn,
Thanks for letting me know. The code is there now: wplearninglab.com/contact-form-7-get-value-from-url/
Let me know if you run into any problems or having any further questions!
Hi, Thank you for the video, i tried exactly how you explained. Edited contact form ID attribute, added script the page, changed the Variable, Parameter and Input. The form is loading fine when called with original URL, but after adding the parameter value and click on Enter, page is showing up 404 error. Can you please suggest what could go wrong, any URL settings etc. Thanks advance for the help
Hi Satya, it sounds like an error when you're testing the url parameters. Make sure they are structured like this:
yourdomain.com/page-slug?fname=Satya&email=email@email.com
The important parts are the ?, the = and the &. Having those in the wrong places will cause a 404.
Let me know how it goes!
Hi, the problem is i have, used the same name for variable also and in CF7 form column name also. That's why 404 error. Now it is working fine. thank you for your swift response. I just have one more question, how to pass an ID value as parameter, which will look into some reference and fetch the other field and fill the form fields. Can you please help how to achieve that
Hi Satya,
I'm glad you got the first problem sorted out!
For the second problem, where is the ID value from the parameter looking up the information?
HI, Thank you for you reply,
Right now My ID value is in Azure SQL Database. It is a database table actually. If we pass ID value as parameter in URL, the URL should refer the table and fetch the Name and Title columns and fill up the Form in wordpress. That is the need. Instead we can also save the table in CSV format, so that we can host the file in FTP and refer the same. Can you please guide me how to achieve that using CF7 and javascript. Thank you very much in advance.
I'm using CF7 and Mautic, and I have a problem that when there is a space in a Name (ex. John Smith), on the form It will input as "John+Smith", so It doesn't read that there is as space in between.
Do you know how to fix it?
I found a solution, I replaced the row 10 with: return sParameterName[1] === undefined ? true : sParameterName[1].replace(/\+/g, " ");
Hi Joaquin,
Sorry for the delay in responding. Thanks for sharing the code and good working finding the solution!
hi, i tried the same thing!! and also did console log
it is showing undefined. it is mainly because i am not able to understand the type of parameter! can someone help me out over here
The pre-submission for contact from 7 it's and available?????
Hi Alinouhou, I'm not sure what you are asking. Can you rephrase?
Hello Sir, This is a good tutorial but can you please guide me further i want to do something like that i have two steps Contact Form 7 form and i put two address fields on first step and i also put these fields on second step and i want if someone come to my website and fill out these fields on first step and click on next so on second step i also put two address fields but i want when the user come on this step so these address fields are auto filled by grabbing the data from first step about which i told you before. So please response me if you have any idea about that. Thanks..
How to run that url without clicking submit button... plzz help
Hi Amanji,
You can make actions happen on the site without submitting and without refreshing a page using AJAX, which JavaScript.
Can you give more details on what you're trying to achieve?
Does this script work on a site that is https ?
How to display an empty field where it will register "undefined"
I'll subscribe if i can get this to work. the js is working for (console.log) but its not pre filling the form
Hi, Thank you for the script, everything work really fine except the date field... please let me know the syntaxe of the URL parameter ie : &date=01/01/2019 this syntaxe is not working cause the slash is considered like the rest of the URL... please let me know how to autofill the date field witch is a calendar picker and only work with manuel fill... thanks !
Less talking please! 9 mins tutorial for a very simple task!
HI, thanx for the tutorial. Very helpful. Thank God for you bro.
You're welcome Daniel, thanks for watching!
Hi, thank you for very helpful tutorial, but when its prefilled its going disappear after page loading finished, how can I solve that , thank you!