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.

Generate Password from Hidden Field

  1. coisty1856
    Member

    Hello,

    Can anybody point me in the right direction to implement using a hidden field to generate a random password when a user submits a form?

    For example, I'd like for the user to submit their name and email address and then have a random password generated that is tied to their email address after they submit the form.

    Thanks!

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  2. Sounds like user registration. Can you use the user registration plugin and rely on WordPress to generate your random password for you?

    If not, you will need some function in your theme's functions.php to generate a random string. What do you need to do with the password once it's generated? Send it in the notification? Just store it in the entry? What will the password be used for?

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  3. You could use the gform_pre_render filter to generate it before the form is shown to the visitor, then just store it with the entry. You can do whatever you want to with it at that point.

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

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  4. coisty1856
    Member

    Thanks @Chris. Using the user registration won't work because the password is needed for use on a third-party site. Once the random password is generated, I need for the information to be sent to an administrator and the user so they can use it on the third-party site.

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  5. OK. You can use the gform_pre_render to generate a password ahead of time, before the form is rendered and displayed to the user. It will be visible in the source of the page if you use a hidden field. Is that a problem? If not a problem, that's what I would do.

    If you do not want to have the password in the form when it's displayed to the user, you can use the gform_pre_submission filter and do the same thing. It just happens after validation, but before the entry is stored. You can create the password at that point and then store it with the entry. It is available for notifications in that way.

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

    You have to come up with your own algorithm to generate the password. Are there any password rules with the 3rd party site?

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink