Avada Forums Community Forum Passing URL params into avada forms

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • bkling
    Participant
    Post count: 1

    Is it possible to pass in query params from the URL to prefill form fields? I know you can scrape them using a hidden field, but i want to map to visible fields the user has to enter.

    For example, i want to send a customer a check-in form that already has his name and email filled out in the form fields, by sending them a URL such as:

    https://mywebiste.com/myform?name=bob&email=bob@aol.com

    and it should fill in:
    Name: bob
    Email: bob@aol.com

    so the user does not have to type it.

    marklchaves
    Participant
    Post count: 873

    Hi,

    I don’t think Avada Forms has built-in support for that yet. But, it’s pretty straightforward with JavaSript.

    Here’s an example of auto-filling an email field with a get query parameter

    
    /**
     * Fill in a form field using a get query parameter.
     *
     * Example URL: http://avada.local/test-form/?email=test%40test.co
     *
     * Result: Email test@test.co
     */
    (function(){
      	if (!document.URL.includes("test-form")) return; // Run on test-form page only.
    	
      	const emailElt = document.querySelector("#email");
      	if (!emailElt) return; // If no email field, bail.
      
      	const urlParams = new URLSearchParams(window.location.search);
    	//const emailVal = decodeURIComponent(urlParams.get('email')); Uncomment if needed.
    	const emailVal = urlParams.get('email');
    	
    	console.log("Filling in the email field with: " + emailVal);
    	
    	if (emailVal) emailElt.value = emailVal;
    })();
    
    

    Tweak as needed.

    Add this to the footer area of your pages using Avada code options or a snippets plugin.

    Cheers!

    nabeelkhan
    Participant
    Post count: 3

    Thank you for the code @marklchaves, I will be really thankful and appreciate if you can help me too.

    I have a WP page with URL like http://abc.com/deal/?fname=FirstName&?lname=LastName&?somevar=SomeVariable, I want the landing page to greet user with his First and Last Name and the variable.

    How can this be done, I am completely new to AVADA and WP, Can you please help out here?

    marklchaves
    Participant
    Post count: 873

    Hello @nabeelkhan,

    Thanks for asking.

    There are a couple of ways to do that. I would go the PHP route for starters.

    Here’s an example PHP filter hook that adds (pre-pends) a personal greeting to a post or page based on the “fname” GET query parameter passed in.

    
    /** Get Query Parameters Example */
    add_filter( 'the_content', function( $the_content ) {
    	$fn = '';
    	if ( isset( $_GET['fname'] ) ) {
    		$fn = "<h2>Yo, " . $_GET['fname'] . "!</h2>";
    	} // if
    	return $fn . $the_content;
    } );
    
    

    The result would look like this.

    https://jmp.sh/ggD5CMq

    Since you’re new to WP, you might want to work with a web developer or learn more about WordPress hooks.

    Cheers!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.