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.

Random chanracters in hidden field

  1. I need to have a set of random characters generated each time the form is accessed and placed in a hidden field in the form.

    I need to have the same random character set sent via email along with the rest of the form details via email to me (but not to the person filling out the form). I then need to have that same character set passed to the "Thank You" page via a shortcode.

    I would like the random character set to be combination of alpha numeric characters and be at least 10 digits if possible.

    Thank you.

    ---
    Robert Basil
    Information Systems Manager
    Plexus Worldwide, Inc.
    7025 East Greenway Parkway
    Suite #250
    Scottsdale, AZ 85254

    Email: robert@plexusworldwide.com
    Phone: 877-281-8333 x110
    Fax: 877-281-8322
    Skype: robertbasil

    Posted 15 years ago on Friday October 23, 2009 | Permalink
  2. Robert,

    Here is what you need to do:

    1- Add the hidden field to your form
    a- Allow it to be populated dynamically (advanced tab)
    b- Type "rand_number" in the "parameter name" text field

    2- Add the following code snippet to your template's function.php file


    add_filter("gform_field_value_rand_number", "populate_rand_number");
    function populate_rand_number(){
    return uniqid();
    }

    3- Configure The form's confirmation page
    a- Select redirect
    b- Enter the url to the thank you page
    b- Check the "Pass field data via query stirng" checkbox
    c- Build your query string by selecting the hidden field from the list of available variables

    4- Configure notifications
    a- Add the "All submitted fields" to the body of the admin notification to receive all fields via email
    b- If you don't want the user to receive an email at all, just leave the subject and body blank for the user notification

    Let us know if you have any problems.

    Good Luck!

    Posted 15 years ago on Sunday October 25, 2009 | Permalink
  3. Ok, got it working where the random string is passed to the URL of the thank you page. How do I display the random string on the Thank You page via shortcode?

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  4. Any ideas on my issue above?

    "How do I display the random string on the Thank You page via shortcode? "

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  5. Are you storing the random string in a hidden field? If so you can display the value of this hidden field using the field variables in the confirmation page text.

    I'm not sure what you mean by displaying the random string on the Thank You page via shortcode. This is outside the scope of the Gravity Forms shortcode which only displays a form, it doesn't do anything with query string parameters.

    You would have to create the random string, populate a hidden field with the random string when the form is submitted and then you can display the value of that form field.

    Alex outlined above how you can accomplish this.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  6. "Are you storing the random string in a hidden field? If so you can display the value of this hidden field using the field variables in the confirmation page text."

    Ok, how do I do this? They way Alex explained it above the hidden field string is displayed in the URL of the conformation page but how do I display it in the page itself?

    I was told in my pre-sales question that this would be possible. Without it the gravityform system will not work for us at all.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  7. I have tried putting both {Hidden Field:6} and [Hidden Field:6] in the confirmation page and neither work.

    Thanks!

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  8. Carl,

    FYI: Here is Alex's answer to my pre-sales question about being able to display the variable on the Thank You page.

    http://forum.gravityhelp.com/topic/php-in-hidden-field-1

    Robert,
    Yes, you can use one of our hooks to dynamically populate hidden fields with any value you want. You will then be able to pass that hidden field value to the thank you page.
    We have some code samples on how to do it, so when you are ready just let me know I will can send to you.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  9. I need to get the working before I leave the office today, so I am just going to use exec_php and some php code to pull the data out of the URL.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  10. Robert, Alex responded in this thread above with instructions. His message begins with "Here is what you need to do:" and outlines what you need to do to populate a hidden field with data using the api hooks.

    It involve adding a hidden field to your form, generating a random string, and then inserting the value of that random string into the hidden field. When the form is submitted, it includes a field that contains your random string.

    Have you done this part yet?

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  11. If you are using page redirection for the confirmation, once Gravity Forms redirects to that page and it is no longer being controlled by Gravity Forms.

    If you are passing data to that page using query string values, you will then need to use PHP to get and display those query string values.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  12. I'm a little confused as to what you are using for a confirmation page. Are you using the built in confirmation page text and the form field variables, or are you redirecting to a page and passing the values in the query string?

    If you are redirecting to a WordPress page and passing the values in a query string you will need to use PHP to pull in those values and display them. Once you redirect to another page it is outside Gravity Forms control so you need to use PHP to manipulate the data in the query string.

    If you are using the built in text confirmation by entering your confirmation text in the form settings, the form field variables should work. If you are doing it this way, are you saying the form field variables for your hidden fields aren't working? If this is this case, have you verified that values exist for those hidden fields by viewing the Entry and checking to see that you are in fact storing the hidden field data?

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  13. Just a quick note, the form field variables such as:

    {Hidden Field:6}

    Are only going to work within Gravity Forms controlled text output such as the Notification emails and the built in Confirmation Text field.

    If you are redirecting to a WordPress page for the confirmation, these don't work as you are redirecting to a WordPress page and Gravity Forms doesn't control this.

    If you are using the redirect and passing data in the query string you will need to use PHP to pull in and display the query string value... or use the built in Confirmation Text capabilities of Gravity Forms.

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  14. Carl,

    Yes, I am sending them to a wordpress page. I'll just pull the variables out of the URL and pass them to the page. We already have a lot of custom php code in this "thank you" page, that is why we can't use the default "Confirmation Text" options.

    Thanks for your help!

    Posted 15 years ago on Monday October 26, 2009 | Permalink
  15. Raintrader
    Member

    Hi Alex,

    i also used te above posted Snippet in my function.php ans it works properly that way.
    Is there a way to influence the random text that is created ?
    Using this function generates text like this : 4af6b98a935f9
    Is it possible to to generate a random numeric string like : 89571547852 instead ?

    Thanx in advance

    Sascha

    Posted 15 years ago on Monday November 9, 2009 | Permalink
  16. Sascha,
    To generate random numbers, replace:

    return uniqid();

    by:

    return mt_rand();

    That should give you numeric numbers instead. You can also control the minimum and maximum number generated by mt_rand() by passing them as parameters. For example: mt_rand(5,15) will generate random numbers between 5 and 15.
    You can find more info on mt_rand() here:
    http://www.php.net/manual/en/function.mt-rand.php

    Good Luck.

    Posted 15 years ago on Monday November 9, 2009 | Permalink
  17. i used uniqid and it works well but i want a shorter id. how can i control the length? i tried something from this page http://us.php.net/manual/en/function.uniqid.php but could not get it to work. help!

    Posted 14 years ago on Tuesday April 27, 2010 | Permalink
  18. Try using mt_rand() instead.
    For example, mt_rand(5,15) will generate random numbers between 5 and 15. You can change the parameters to whatever numbers you need.

    You can find more info on mt_rand() here:
    http://www.php.net/manual/en/function.mt-rand.php

    Posted 14 years ago on Wednesday May 5, 2010 | Permalink
  19. but how can i make sure that number has not been used before? it needs to be unique and sort and random...

    Posted 14 years ago on Monday June 28, 2010 | Permalink
  20. It looks like you will need to make a decision here. You won't be able to have a short and unique number, simply because there are so many combinations a short number will be able to support.
    If you need the numbers to be unique and random, my suggestion is to use uniqid(). The number will be large, but that's the price you pay to have an unique number.

    Posted 14 years ago on Monday June 28, 2010 | Permalink
  21. ok. all my numbers generated with uniqid start with 4c since they seem to be based on a timestamp. doesn't feel very random that way but it's good enough. thanks.

    Posted 14 years ago on Tuesday June 29, 2010 | Permalink