Contact Form 7 Get Value From URL Using Javascript & Autofill Fields Dynamically

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • Grab Your Free 17-Point WordPress Pre-Launch PDF Checklist: wplearninglab....
    Contact Form 7 Get Value From URL Using Javascript & Autofill Fields Dynamically • Contact Form 7 Get Val...
    Blog post with code: wplearninglab....
    Join our private Facebook group today! / wplearninglab
    How to prefill contact form 7 fields with values from the URL. This method works with all types of forms, not only contact form 7. This contact form 7 get value from URL tutorial will provide you with all Javascript you need to make it work.
    Exclusive for WPLearningLab viewers, up to 50% off hosting: wplearninglab....
    Stop brute force attacks before they happen with this workshop: wplearninglab....
    Grab your free 17-Point WordPress Pre-Launch PDF Checklist: vid.io/xqRL
    Download your exclusive 10-Point WP Security Checklist: bit.ly/10point-...
    Subscribe to this awesome channel here: www.youtube.com...

Komentáře • 105

  • @wplearninglab
    @wplearninglab  Před 6 lety +1

    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: czcams.com/video/wy70WGCjMY4/video.html

  • @sangamadhikari8497
    @sangamadhikari8497 Před 4 lety +1

    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.

  • @faizaabdullah2678
    @faizaabdullah2678 Před 3 lety +1

    Thank you Boss You have saved my life..

    • @wplearninglab
      @wplearninglab  Před 3 lety

      I’m happy to help Faiza, thanks for watching!

  • @iBuyAnyCom
    @iBuyAnyCom Před rokem

    This video is amazing - WORKED PREFECTLY - thank you!

  • @TheSeeker2013
    @TheSeeker2013 Před 5 lety +3

    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.

  • @koppjoseph
    @koppjoseph Před 3 lety +1

    This was incredibly helpful.

  • @charlesachez7508
    @charlesachez7508 Před 5 lety +3

    i want user re-driected to form pre-filled in another page that has the CF7 form when button is clicked

  • @RadicalNetrunner
    @RadicalNetrunner Před 5 lety +2

    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.

    • @markbenitez8493
      @markbenitez8493 Před 5 lety

      I have the same problem and I don't know how to fix it ..
      you can help? Thank you!

  • @danielkasanga2139
    @danielkasanga2139 Před 5 lety +1

    HI, thanx for the tutorial. Very helpful. Thank God for you bro.

  • @weyou
    @weyou Před 4 lety +1

    Works pretty perfect! Thanks!

    • @wplearninglab
      @wplearninglab  Před 4 lety

      You’re welcome Martin, thanks for watching!

  • @bpz89
    @bpz89 Před 3 lety +1

    Hi I am having an issue where the variable enters into the field, but quickly disappears. Any idea what's going on?

  • @mrtshepo4216
    @mrtshepo4216 Před 2 lety

    great tutorial thats

  • @andrew-isac
    @andrew-isac Před 4 lety +1

    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

  • @minecraftwordpress67
    @minecraftwordpress67 Před 4 lety +1

    kindly make dropdown tutorial auotfill

  • @heysoulfulsinger4595
    @heysoulfulsinger4595 Před 3 lety

    Saviour thanks man!!

  • @HMIBarryLSalter
    @HMIBarryLSalter Před 6 lety +3

    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!!

    • @wplearninglab
      @wplearninglab  Před 6 lety

      Hi Barry,
      Good call, I messed that up. Sorry!
      I'm updating the blog post soon.

  • @ShitalHorte
    @ShitalHorte Před 6 lety +1

    Thank you so much for this video, I was trying very hard to autofill fields work.

    • @wplearninglab
      @wplearninglab  Před 6 lety

      You're welcome Shital, did you get the autofill working with the help of this tutorial?

  • @GembelKreative
    @GembelKreative Před 2 lety

    This is work thanks sir 😁👍👍

  • @MyPerfectTrade
    @MyPerfectTrade Před 4 lety +1

    Very informative indeed.But can you tell the code for for field to take up values from google sheets.

  • @andonisr
    @andonisr Před 3 lety +1

    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!!!!!

  • @patrycja605
    @patrycja605 Před 5 lety

    Thank you so much for the tutorial.

  • @LucasMatosdesigner
    @LucasMatosdesigner Před 5 lety +1

    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?

  • @Veron988
    @Veron988 Před 6 lety +1

    Bjorn you are a good block

    • @wplearninglab
      @wplearninglab  Před 6 lety +1

      haha @ "block" Vern, I love it. I'm glad you didn't edit it this time :)

    • @Veron988
      @Veron988 Před 6 lety +1

      Lol and thx for another great tutorial

  • @madhavi6763
    @madhavi6763 Před 3 lety +3

    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?

    • @wplearninglab
      @wplearninglab  Před 3 lety +2

      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!

    • @erikaklink6799
      @erikaklink6799 Před 3 lety

      Have You found a solution to your question yet? I'm currently trying to do the same thing.

    • @akhileshkesharwani9209
      @akhileshkesharwani9209 Před 2 lety

      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 🙏🏻

  • @case_tips
    @case_tips Před 2 lety +1

    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!

  • @luisbrito7098
    @luisbrito7098 Před 5 lety +1

    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?

  • @shanra4764
    @shanra4764 Před 5 lety +1

    How do you get values from wp database? Nice video.

  • @g3thammered
    @g3thammered Před 3 lety

    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.

  • @ArrepiaB
    @ArrepiaB Před rokem

    How would you do the same to prepopulate the Registration form of woocommerce? I can’t find where to insert the js

  • @marpiemar
    @marpiemar Před 4 lety

    Thank you, does it works with radio elements?

  • @drewclifton610
    @drewclifton610 Před 2 lety

    Hi thanks for sharing this! Could you explain how to pre-check a checkbox? Thanks so much.

    • @drewclifton610
      @drewclifton610 Před 2 lety

      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!

  • @scottheliker5948
    @scottheliker5948 Před 4 lety +2

    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 ?

    • @wplearninglab
      @wplearninglab  Před 4 lety

      Hi Scott,
      Great addition to the script. I'll update the code on the website.
      This tutorial ( czcams.com/video/YL6C0NzRsgI/video.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!

  • @meharabdullah7127
    @meharabdullah7127 Před 3 lety

    Will this work on caldera forms ??

  • @babsake
    @babsake Před 6 lety +1

    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

    • @wplearninglab
      @wplearninglab  Před 6 lety +1

      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!

    • @Toonzy1000
      @Toonzy1000 Před 5 lety

      ​@@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

  • @drewclifton610
    @drewclifton610 Před 2 lety

    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.

  • @ajayrohera1563
    @ajayrohera1563 Před 4 lety

    Thanks for sharing this. Can you please share the script for getting the entire url as well?

  • @pleaseconnectme7003
    @pleaseconnectme7003 Před 4 lety

    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?

  • @faizaabdullah2678
    @faizaabdullah2678 Před 3 lety

    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?

  • @BeProfette
    @BeProfette Před 5 lety +1

    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... :(

  • @charlesachez7508
    @charlesachez7508 Před 5 lety +1

    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

    • @wplearninglab
      @wplearninglab  Před 5 lety

      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!

  • @TheWaqaspuri
    @TheWaqaspuri Před 4 lety

    Is it possible, if plugin can do that for Divi (elegant themes)

  • @marcialeger
    @marcialeger Před 4 lety +1

    Is there an update to the script? It did work a few months ago but I cannot make it work now.

  • @farhanawan5590
    @farhanawan5590 Před 4 lety +1

    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 ?

    • @wplearninglab
      @wplearninglab  Před 4 lety

      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!

    • @farhanawan5590
      @farhanawan5590 Před 4 lety

      @@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

  • @MartinYankov
    @MartinYankov Před 3 lety

    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?

  • @classyshots9237
    @classyshots9237 Před 5 lety +1

    hi there..can we autofill html form field elements to the containing api form

    • @wplearninglab
      @wplearninglab  Před 5 lety

      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.

  • @haziqsiddiqui5237
    @haziqsiddiqui5237 Před 6 lety

    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.

  • @martinschmidt1652
    @martinschmidt1652 Před 4 lety +1

    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 =/

    • @wplearninglab
      @wplearninglab  Před 4 lety

      Hey Martin,
      If you open the 'inspector' in your browser, are you seeing any errors in the 'console' tab?

    • @justaguywithaunibrow
      @justaguywithaunibrow Před 4 lety

      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.

    • @martinschmidt1652
      @martinschmidt1652 Před 4 lety

      @@wplearninglab and this is in the form
      [text* item id:urlitem placeholder "exempel: Kajak, handväska, sommarhus, drönare"]

  • @knuevenermackert1164
    @knuevenermackert1164 Před 4 lety

    Hi! In arrays my square brackets [i] get escapted to [i] What can I do?

  • @akramriyo8742
    @akramriyo8742 Před 5 lety

    how to send one wordpress form value to next wordpress form (textbox to textbox print) please help me

  • @harsh8580
    @harsh8580 Před 4 lety

    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

  • @HealCorrectlyCom
    @HealCorrectlyCom Před 6 lety +1

    Is there anyway to do this easier with a product page and say a coupon code pre-filled into the box?

    • @wplearninglab
      @wplearninglab  Před 6 lety +2

      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!

    • @HealCorrectlyCom
      @HealCorrectlyCom Před 6 lety +1

      Thank you for the reply! I'll give it a shot and see how it works out! Big thumbs up and subbed!

    • @wplearninglab
      @wplearninglab  Před 6 lety

      Thanks for the sub, much appreciated! Let me know how it goes :)

  • @GosuMania
    @GosuMania Před 4 lety

    Hi mate, can i autofill Fileds with value from a file php or xml on my website?

  • @shawnwatts3884
    @shawnwatts3884 Před 4 lety +1

    Can you update the blog page because the code is now missing?

    • @wplearninglab
      @wplearninglab  Před 4 lety +2

      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!

  • @shahsyed776
    @shahsyed776 Před 6 lety

    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..

  • @satyaramesh230
    @satyaramesh230 Před 6 lety +1

    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

    • @wplearninglab
      @wplearninglab  Před 6 lety

      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!

    • @satyaramesh230
      @satyaramesh230 Před 6 lety

      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

    • @wplearninglab
      @wplearninglab  Před 6 lety

      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?

    • @satyaramesh230
      @satyaramesh230 Před 6 lety

      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.

  • @charlesachez7508
    @charlesachez7508 Před 5 lety +1

    Help..How do i button click and get URL value to pre-fill in contact form 7

    • @wplearninglab
      @wplearninglab  Před 5 lety

      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?

    • @charlesachez7508
      @charlesachez7508 Před 5 lety

      ​@@wplearninglab i want it pre-filled in another page that has the CF7 form when button is clicked

  • @yehudaclinton6252
    @yehudaclinton6252 Před 5 lety

    I'll subscribe if i can get this to work. the js is working for (console.log) but its not pre filling the form

  • @YairShiloach
    @YairShiloach Před 5 lety

    How to display an empty field where it will register "undefined"

  • @simas2313
    @simas2313 Před 5 lety +1

    How to run that url without clicking submit button... plzz help

    • @wplearninglab
      @wplearninglab  Před 5 lety +1

      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?

  • @joacogaray
    @joacogaray Před 6 lety

    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?

    • @joacogaray
      @joacogaray Před 6 lety +1

      I found a solution, I replaced the row 10 with: return sParameterName[1] === undefined ? true : sParameterName[1].replace(/\+/g, " ");

    • @wplearninglab
      @wplearninglab  Před 6 lety

      Hi Joaquin,
      Sorry for the delay in responding. Thanks for sharing the code and good working finding the solution!

  • @alinouhoualinouhou4258

    The pre-submission for contact from 7 it's and available?????

    • @wplearninglab
      @wplearninglab  Před 6 lety

      Hi Alinouhou, I'm not sure what you are asking. Can you rephrase?

  • @marcialeger
    @marcialeger Před 4 lety

    Does this script work on a site that is https ?

  • @Pegasedavid
    @Pegasedavid Před 5 lety

    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 !

  • @LucaCrippa88
    @LucaCrippa88 Před 3 lety

    Less talking please! 9 mins tutorial for a very simple task!

  • @Dewdan1
    @Dewdan1 Před 5 lety

    Thank you for this great tutorial, all working great.

  • @case_tips
    @case_tips Před 2 lety

    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!