How to make a referral url get injected to opt in form?

by 13 replies
15
Hey guys,
Got a question.
I want to start an affiliate site but I want to I guess you would call inject certain variables into a opt in form so when a person opt ins it goes to that affiliate. So say the url is yourwebite.com/?ref=ixxx&fid=xxxx0&cc=exxxx I need these 3 variables passed to the opt in form. I've spent a few days trying to figure out how to do this. Anyone help please?
#programming #form #injected #make #opt #referral #url
  • <?php

    //grab the affilliate id from the url
    // yourwebsite.com?id=123
    $id = $_GET['id'];

    ?>

    <form>
    //place your other form fields here
    <input type="hidden" name="affiliateid" value="<?php echo $id; ?>">
    </form>

    A variable stored in a url like you want is called a GET variable. Look it up.
    • [1] reply
    • this is on wordpress it will work?
  • The basics behind doing it are still the same. Except because you are using wordpress it makes it more complicated (ie: where you can put the code). I would imagine there is already a plugin to do what you want.
    • [1] reply
    • <form method="post" action="http://website.com/subscribe.php"> <input type="hidden" name="CampaignCode" value="a53779680753" /> <input type="hidden" name="FormId" value="893879" /> <input type="hidden" name="PassFormData" value="1" /> <input type="hidden" name="TrackerName" value="ref" /> <input type="hidden" name="AffiliateName" value="incomedream" /> <table align="center"> <tr> <td>Email:</td><td><input type="text" name="Email" /></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="Submit" /></td> </tr> </table> <img src="http://www.website;c0m.com/show_form.php?id=893879" /> </form>

      Here is the form how would i do this? Sorry to bug you
      i need to campaign code, formid, and affiliatename passed from url to opt in box
  • Ok i kind of got it.. I placed
    [code]add_filter('query_vars', 'parameter_queryvars' );
    function parameter_queryvars( $qvars )
    {
    $qvars[] = 'refid';
    return $qvars;
    }

    function echorefid()
    {
    global $wp_query;
    if (isset($wp_query->query_vars['refid']))
    {
    print $wp_query->query_vars['refid'];
    }
    }[code]
    In tthe functions.php but i want to pass 3 variables how can i do that?
  • So it would be something like this:


    if (isset($wp_query->query_vars['refid'])) {
    //set the refid to a variable for easier use later
    $refid = $wp_query->query_vars['refid'];
    }


    and then in your form you need to echo out this variable into the value attribute

    <input type="hidden" name="TrackerName" value="<?php echo $refid; ?>" />

    Tip: change the input type from "hidden" to "text" so you can view if the variables are being passed.
    • [1] reply
    • Im dumb with code lol sorry.. Ok so how will all 3 variables get passed from url to my opt in form. Wont they all say the same variable?
      I echoed it out into all 3 fields and it came up as the same thing.
      • [1] reply
  • So in your URL you have three GET variable

    yourwebite.com/?ref=ixxx&fid=xxxx0&cc=exxx

    1. ref (which equals ixxx)
    2. fid (which equals xxxx)
    3. cc (which equals exxx)

    So in your code right now you are only grabbing the ref variable and echoing that variable. Do the same thing for the other two variables fid & cc.

    In your code you are also using 'refid' which isn't even a variable in the url you supplied.
  • Ok so how do I do tha tthen? do i just put <?php echofid();?>for the fid value or do i have to change something in the functions?
  • if (isset($wp_query->query_vars['ref'])) {
    //set the ref to a variable for easier use later
    $ref= $wp_query->query_vars['ref'];
    }
    if (isset($wp_query->query_vars['fid'])) {
    //set the fid to a variable for easier use later
    $fid= $wp_query->query_vars['fid'];
    }
    if (isset($wp_query->query_vars['cc'])) {
    //set the refid to a variable for easier use later
    $cc = $wp_query->query_vars['cc'];
    }

    With the above I am assuming $wp_query->query_vars['variable'] is grabbing the get variable because that is the code you supplied.

    So then we can take all those values from above and echo them into the right form inputs

    value="<?php echo $ref;?>"
    value="<?php echo $fid;?>"
    value="<?php echo $cc;?>"

    If you still don't understand, do some research because that's as simple as it's gonna get.
  • I got what you mean. I added that first part into functions and added the value. Heres the problem what is this code supposed to look like?
    add_filter('query_vars', 'parameter_queryvars' );
    function parameter_queryvars( $qvars )
    {
    $qvars[] = 'refid';
    return $qvars;
    }

    function echorefid()
    {
    global $wp_query;
    if (isset($wp_query->query_vars['refid']))
    {
    print $wp_query->query_vars['refid'];
    }
    }


    Its not calling the variables and i think its somethng to do with this code?
  • I got it man thanks soooo much for your help!
    had to add the qvars for each one

Next Topics on Trending Feed

  • 15

    Hey guys, Got a question. I want to start an affiliate site but I want to I guess you would call inject certain variables into a opt in form so when a person opt ins it goes to that affiliate. So say the url is yourwebite.com/?ref=ixxx&fid=xxxx0&cc=exxxx I need these 3 variables passed to the opt in form. I've spent a few days trying to figure out how to do this. Anyone help please?