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.

Help with user ID creation

  1. rusjames
    Member

    I need help with adding some functionality to my form (if possible) my form is at http://www.airsimcorp.com/registration
    I need a few things if anyone can help a image to help see what I am talking about is at http://rus.tinygrab.com/bDzy
    1. I need to take data for three fields in my form and spit out a user ID for the person registering. I need it to be displayed on the Thank you for registering page after they register and also add them to my user list and send them an email with there user ID. I am using the user registation add-on. The user does not need a password (because they are not going to be using the user ID to log on to my website) but i would like one created for later use.

    2. I am using a number generator widget with my for to create a random number for there user ID (one of the pieces of data that I am using to create the user ID) I need a way to check that the number that is generated is the number that they are entering into the field unless there is a way to generate a random number automatically then I can remove the widget and the number field and make things completely that much easier.

    A little side note I am not a coder (yet want to learn) and do not know much with the guts of Wordpress so if coding and diving into the guts of Wordpress is involved I will need help with the code and where to put it so that will work. Or if someone is willing to teach me what I need to do that will be very helpful and appreciated.

    Rus

    Posted 8 years ago on Monday January 23, 2012 | Permalink
  2. Hi Rusjames,

    When you say user ID it sounds like you're actually talking about a username. The user ID is controlled by WordPress and will be whatever the next available ID is in the wp_user table.
    If you'd like to generate a dynamic user name based on a variety of parameters, I'd suggest checking out the gforms_username filter.

    http://www.gravityhelp.com/documentation/page/Gform_username

    This filter will allow you to create a custom function to alter the username based on your own parameters. The $entry object is passed so you can pull submitted field values and create a custom username based on them.

    Posted 8 years ago on Wednesday January 25, 2012 | Permalink
  3. rusjames
    Member

    Thank you David for getting back to me a couple of things i am not sure how to code it to the the way that i would like and even where to put the code after it was coded is there anyway that you can give me at least a start so that I can see how to make the changes that are needed?

    This would be very helpful and appreciated.

    Rus

    Posted 8 years ago on Wednesday January 25, 2012 | Permalink
  4. Hi Rusjames,

    The code would go in your theme's functions.php file. A good base to start from would be to use the example code provided at the bottom of the gform_username documentation. You'll want to modify your filter slightly in order to pass the parameters to your function:

    [php]
    add_filter('gform_username', 'your_function_name', 10, 4);
    function your_function_name($username, $config, $form, $entry) {
       ...
    }

    Also, I neglected to mention that you likely need an unreleased version of the User Registration Add-on. Send me an email at david@rocketgenius.com and I will send this to you.

    Posted 8 years ago on Wednesday January 25, 2012 | Permalink
  5. Hi Rusjames,

    Not sure if this is something you might be interested in but we use the below code which you would place in your functions folder to generate a random 8 digit number with a prefix( in the below sample the prefix is ebar." You would want to update that with what ever you would want. As well as change the form_id to the form number you are using and the field_id with the id of the form field your trying to populate with the random number.

    Then under that specific field you would want to modify the entry to check the box that says "Allow field to be populated dynamically " then in the field provided add the letters "uuid" without quotes. You can make this field admin only or allow them to see it but either way you will get a random unique id that can then be used in any fashion you would like.

    Hope this gets you a little closer and is what you were looking for.

    add_filter("gform_field_value_uuid", "get_unique");

    function get_unique(){

    $prefix = "eBar"; // update the prefix here

    do {
    $unique = mt_rand();
    $unique = substr($unique, 0, 8);
    $unique = $prefix . $unique;
    } while (!check_unique($unique));

    return $unique;
    }

    function check_unique($unique) {
    global $wpdb;

    $table = $wpdb->prefix . 'rg_lead_detail';
    $form_id = 7; // update to the form ID your unique id field belongs to
    $field_id = 1; // update to the field ID your unique id is being prepopulated in
    $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");

    if(empty($result))
    return true;

    return false;
    }

    Posted 8 years ago on Wednesday January 25, 2012 | Permalink
  6. rusjames
    Member

    David in this line of code add_filter('gform_username', 'userID', 10, 4); what does the 10,4 mean?

    Posted 8 years ago on Thursday January 26, 2012 | Permalink
  7. The 10 is the priority (10 is the default priority) and the 4 is the number of arguments you must send to the function.

    $username, $config, $form, $entry

    You can read about it here:
    http://codex.wordpress.org/Function_Reference/add_filter

    This is WordPress functionality, not Gravity Forms specific.

    Posted 8 years ago on Tuesday January 31, 2012 | Permalink