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

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 105

  • @wplearninglab
    @wplearninglab  6 років тому +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: ua-cam.com/video/wy70WGCjMY4/v-deo.html

  • @sangamadhikari8497
    @sangamadhikari8497 4 роки тому +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.

  • @iBuyAnyCom
    @iBuyAnyCom Рік тому

    This video is amazing - WORKED PREFECTLY - thank you!

  • @TheSeeker2013
    @TheSeeker2013 5 років тому +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.

  • @faizaabdullah2678
    @faizaabdullah2678 3 роки тому +1

    Thank you Boss You have saved my life..

    • @wplearninglab
      @wplearninglab  3 роки тому

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

  • @charlesachez7508
    @charlesachez7508 5 років тому +3

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

  • @andrew-isac
    @andrew-isac 4 роки тому +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

  • @GembelKreative
    @GembelKreative 3 роки тому

    This is work thanks sir 😁👍👍

  • @andonisr
    @andonisr 4 роки тому +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!!!!!

  • @koppjoseph
    @koppjoseph 3 роки тому +1

    This was incredibly helpful.

    • @wplearninglab
      @wplearninglab  3 роки тому

      Thanks Joseph and thanks for watching!

  • @RadicalNetrunner
    @RadicalNetrunner 5 років тому +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 5 років тому

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

  • @weyou
    @weyou 5 років тому +1

    Works pretty perfect! Thanks!

    • @wplearninglab
      @wplearninglab  5 років тому

      You’re welcome Martin, thanks for watching!

  • @HMIBarryLSalter
    @HMIBarryLSalter 6 років тому +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  6 років тому

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

  • @luisbrito7098
    @luisbrito7098 6 років тому +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?

  • @madhavi6763
    @madhavi6763 4 роки тому +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  4 роки тому +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 3 роки тому

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

    • @akhileshkesharwani9209
      @akhileshkesharwani9209 2 роки тому

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

  • @MyPerfectTrade
    @MyPerfectTrade 5 років тому +1

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

  • @heysoulfulsinger4595
    @heysoulfulsinger4595 3 роки тому

    Saviour thanks man!!

  • @LucasMatosdesigner
    @LucasMatosdesigner 6 років тому +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?

  • @meharabdullah7127
    @meharabdullah7127 3 роки тому

    Will this work on caldera forms ??

  • @ShitalHorte
    @ShitalHorte 6 років тому +1

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

    • @wplearninglab
      @wplearninglab  6 років тому

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

  • @Dewdan1
    @Dewdan1 5 років тому

    Thank you for this great tutorial, all working great.

  • @marpiemar
    @marpiemar 4 роки тому

    Thank you, does it works with radio elements?

  • @patrycja605
    @patrycja605 5 років тому

    Thank you so much for the tutorial.

  • @ArrepiaB
    @ArrepiaB Рік тому

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

  • @bpz89
    @bpz89 3 роки тому +1

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

  • @case_tips
    @case_tips 2 роки тому +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!

  • @drewclifton610
    @drewclifton610 2 роки тому

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

    • @drewclifton610
      @drewclifton610 2 роки тому

      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!

  • @mrtshepo4216
    @mrtshepo4216 3 роки тому

    great tutorial thats

  • @faizaabdullah2678
    @faizaabdullah2678 3 роки тому

    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?

  • @g3thammered
    @g3thammered 3 роки тому

    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.

  • @shanra4764
    @shanra4764 5 років тому +1

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

  • @GosuMania
    @GosuMania 4 роки тому

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

  • @marcialeger
    @marcialeger 5 років тому +1

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

  • @TheWaqaspuri
    @TheWaqaspuri 4 роки тому

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

  • @babsake
    @babsake 6 років тому +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  6 років тому +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 5 років тому

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

  • @pleaseconnectme7003
    @pleaseconnectme7003 5 років тому

    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?

  • @farhanawan5590
    @farhanawan5590 5 років тому +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  5 років тому

      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 5 років тому

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

  • @Veron988
    @Veron988 6 років тому +1

    Bjorn you are a good block

    • @wplearninglab
      @wplearninglab  6 років тому +1

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

    • @Veron988
      @Veron988 6 років тому +1

      Lol and thx for another great tutorial

  • @scottheliker5948
    @scottheliker5948 5 років тому +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  5 років тому

      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!

  • @charlesachez7508
    @charlesachez7508 5 років тому +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  5 років тому

      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!

  • @classyshots9237
    @classyshots9237 5 років тому +1

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

    • @wplearninglab
      @wplearninglab  5 років тому

      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.

  • @BeProfette
    @BeProfette 6 років тому +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... :(

  • @ajayrohera1563
    @ajayrohera1563 4 роки тому

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

  • @knuevenermackert1164
    @knuevenermackert1164 4 роки тому

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

  • @HealCorrectlyCom
    @HealCorrectlyCom 6 років тому +1

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

    • @wplearninglab
      @wplearninglab  6 років тому +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 6 років тому +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  6 років тому

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

  • @MartinYankov
    @MartinYankov 4 роки тому

    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?

  • @minecraftwordpress67
    @minecraftwordpress67 4 роки тому +1

    kindly make dropdown tutorial auotfill

  • @drewclifton610
    @drewclifton610 2 роки тому

    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.

  • @martinschmidt1652
    @martinschmidt1652 4 роки тому +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  4 роки тому

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

    • @justaguywithaunibrow
      @justaguywithaunibrow 4 роки тому

      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 4 роки тому

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

  • @haziqsiddiqui5237
    @haziqsiddiqui5237 6 років тому

    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.

  • @charlesachez7508
    @charlesachez7508 5 років тому +1

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

    • @wplearninglab
      @wplearninglab  5 років тому

      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 5 років тому

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

  • @akramriyo8742
    @akramriyo8742 6 років тому

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

  • @shawnwatts3884
    @shawnwatts3884 4 роки тому +1

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

    • @wplearninglab
      @wplearninglab  4 роки тому +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!

  • @satyaramesh230
    @satyaramesh230 6 років тому +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  6 років тому

      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 6 років тому

      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  6 років тому

      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 6 років тому

      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.

  • @joacogaray
    @joacogaray 6 років тому

    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 6 років тому +1

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

    • @wplearninglab
      @wplearninglab  6 років тому

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

  • @harsh8580
    @harsh8580 4 роки тому

    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

  • @alinouhoualinouhou4258
    @alinouhoualinouhou4258 6 років тому

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

    • @wplearninglab
      @wplearninglab  6 років тому

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

  • @shahsyed776
    @shahsyed776 6 років тому

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

  • @simas2313
    @simas2313 5 років тому +1

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

    • @wplearninglab
      @wplearninglab  5 років тому +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?

  • @marcialeger
    @marcialeger 5 років тому

    Does this script work on a site that is https ?

  • @YairShiloach
    @YairShiloach 5 років тому

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

  • @yehudaclinton6252
    @yehudaclinton6252 5 років тому

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

  • @Pegasedavid
    @Pegasedavid 6 років тому

    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 3 роки тому

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

  • @danielkasanga2139
    @danielkasanga2139 5 років тому +1

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

    • @wplearninglab
      @wplearninglab  5 років тому

      You're welcome Daniel, thanks for watching!

  • @case_tips
    @case_tips 2 роки тому

    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!