PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

How to permanently hook a piece of data linked to a specific user

  1. ronboyd
    Member

    First off forgive me if this is answered anywhere and just point me to the post (I have searched I promise).

    I'm setting up a membership site and have used GF to collect some extra data that we need to give the site a better function. In a nutshell I have collected an affiliate ID and I would like to now use that data to form an affiliate link that will be displayed at the top of every post/page that that particular user visits so that it is always available to them but only them.

    I have some limited coding knowledge but I do follow instruction very well.

    The information is collected in a simple 3 field form which I have prepopulated the name field with {user:user_login}. The form works and collects the data I require and then redirects to where I want it to.

    Now I want to work out how to tie that information to that particular user and then display it in the manner already mentioned.

    So any clues or help is greatfully accepted.

    Regards Ron

    Posted 13 years ago on Tuesday December 28, 2010 | Permalink
  2. How are users being created? Are you using the User Registration Add-On to create users or are users initially being created another way or may already exist?

    Posted 13 years ago on Tuesday December 28, 2010 | Permalink
  3. ronboyd
    Member

    I knew I would miss something out sorry !

    The users are created via Wishlist membership software unfortunately their registration form is encrypted so I can't add any extra fields to that so instead I have them directed straight to a page with the afforementioned GF on it which I have just three fields on.

    Name which I prepopulate with {user:user_login}
    Phone user entry
    Affiliate ID user entry

    So I need to pass the affiliate ID tied to the specific user so I can use it to build a complete affilate link for them on every post/page for reference. Which will of course be there everytime they login.

    Hope that better explains things.

    Cheers Ron

    Posted 13 years ago on Tuesday December 28, 2010 | Permalink
  4. http://pastie.org/1412228

    Part One: Tying the Affiliate ID to the User

    To tie the affiliate ID we'll trigger a function when the form is submitted using the gform_post_submission hook. In this function, we will get the current user's ID and the affiliate ID as it was submitted to the form entry. We can then add the affiliate ID as a new custom meta item to the current user. There are a few pieces of this you'll need to update to be compatible with your setup.

    add_action("gform_post_submission_7", "set_affiliate_id");

    Update the '7' to the ID of your form.

    $aff_id = $entry[1];

    Update the '1' to the ID of the field you prepopulated with the affiliate ID. You can find this ID by viewing the source code of the page displaying the form and finding the field in the source. The naming format will look like something like this: input_7_1 where the 7 is the form ID and the 1 is the field ID.

    Part Two: Displaying the Affiliate ID

    I've created a simple function that will let you display the affiliate ID stored in the database for the current user. To use this function just call it like this:

    <?php
    
    echo "Affiliate ID: " . get_user_affiliate_id();
    
    ?>

    From the sounds of it, you've got the prepopulation part of this figured out already, but if you need any help with that just let me know.

    Posted 13 years ago on Tuesday December 28, 2010 | Permalink