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.

Issue with gform_after_submission Hook and User Registration and Sending Emails

  1. theslink2000


    This is a little bit complicated so please bear with me.

    Basically I've been trying to sort out my confirmation emails that get sent when a user registers. The email routing included in Gravity Forms is good but it isn't customisable enough for me needs so I've been trying to write my own. I think the code is simple enough but I've run into a bit of a confusing wall.

    My first plan was to write a custom plugin to override the wp_new_user_notification function, as per the Wordpress documentation. Here are my efforts:

    It worked fine and routed the correct emails to the correct places. The problem I encountered here was that I couldn't access extra user metadata captured at the same time as registration, so after feeling like it was a dead end I used the plugin to simply disable the function in favour of using the gform_after_submission hook to send the emails on for completion, this way all metadata is already stored.

    I've been working at it and it's working fine for one type of user registration, seen here:

    However, when I've been trying to mimic the functionality with the other user type I keep hitting errors. The main issue is that

    $user = new WP_User($entry[24]); //Take the $user_id and use the WP_User function to access all information about the newly registered user

    is returning false. So I've tried using

    $user = get_user_by('login', $entry[15]); //Find the user data

    but this just returns NULL. How does this make any sense when it works perfectly in the other example? I've tweeked it around a lot, here's where I am right now:

    Can anyone help me with this, I've been going round in circles for hours now and I can't make any sense of it. I've tried putting in a usleep() to make sure it isn't just taking a little too long but to no avail.

    A live test is online but please PM me for access as I don't want it posted publicly.

    Many thanks.

    Posted 9 years ago on Wednesday December 12, 2012 | Permalink
  2. Looking at this code:

    If you have hooked your function to gform_after_submission, you should be passing it two parameters, $entry and $form. Like this:

    add_action('gform_after_submission', 'patient_registration_confirmation', 10, 2);
    function patient_registration_confirmation ($entry, $form){

    Also, what does $entry[24] contain on the first line of your function? Can you be sure the user ID is present?

    Finally, but unrelated, you should probably quote the field ID when it's not an integer, as in line 8:

    Posted 9 years ago on Thursday December 13, 2012 | Permalink
  3. theslink2000

    Hi Chris,

    Thanks for getting back to me so quickly. Sadly I'm still stuck though.

    I thought both $entry and $form were optional when calling gform_after_submission, which is why it was left out, but on your advise I added a call to it and it generated this error message before outputting my var_dumps:

    Warning: Missing argument 2 for patient_registration_confirmation()

    Apart from that no change.

    As for $entry[24], it is 100% guaranteed as it is set by the site not the user and I have triple checked it by making the code dump it out at this stage, and as I said the same trick worked for the other type of registration.

    As for the quoting decimal entry's thanks for pointing that out, I'd missed that.

    Any more ideas bud?

    Posted 9 years ago on Thursday December 13, 2012 | Permalink
  4. Can you post the complete code you're using, including the action or filter, and your function? I think I am not seeing the complete picture and we're assuming different things.

    I have no doubt $entry['24'] is being set, but I am wondering what the value of it is right on line 2 of your function. Can you echo it, or dump the whole $entry object, to see what it contains?

    Posted 9 years ago on Thursday December 13, 2012 | Permalink
  5. theslink2000

    Here's the complete file for the emailing out on form submission:

    Here's the code powering the form, specifically look at the patient id number section;

    $entry can dump fine, here is an example I've just done:

    Please forgive the mess they're in, it's still all a work in progress.

    Posted 9 years ago on Thursday December 13, 2012 | Permalink
  6. It seems to me that $entry[24] is "PL21NT-015", but that is not a WordPress user ID.

    [24]=> string(10) "PL21NT-015"

    Am I misreading your code?

    Posted 9 years ago on Monday December 17, 2012 | Permalink
  7. theslink2000

    Sorry Chris, I didn't get an email telling me you'd replied.

    That is the user id of the user being created during the registration process powered by this form. So you're right in that the user wouldn't exist at the start, hence the code has picked that user id, but by the time the gform_after_submission hook is fired it should be registered and in place. This is exactly how the home registration works and it doesn't cause an issue with that form. As you can see from this screenshot the user is registered correctly:

    But you're right in as much as the lack of that being a registered user would be the cause, but why does it not see it as a registered user when it is registering the user, if you see what I mean.

    Posted 9 years ago on Friday December 21, 2012 | Permalink
  8. That is the user id of the user being created during the registration process powered by this form.

    It's not the user ID, which in WordPress would be numeric. It's the user login, isn't it? Can you try this way?

    $user = new WP_User_Query( array( 'login' =>  $entry[24] ) );

    I'm confused where the user login is stored in the entry. Is it $entry[15] or $entry[24]? Seems like I have seen reference to it in the code both ways? I might be confused on user ID vs user login.

    Posted 9 years ago on Friday December 21, 2012 | Permalink
  9. theslink2000

    $entry[24] is correct. $entry[15] is a different function that registers a different type of user under different circumstances, but on that form it serves identical purpose.

    I tried your suggestion and it simply outputs every users information. The exception is that the final entry is the login of the newly registered user but there is no more information given on the new user.

    But this seems to be progress. Any more ideas bud?

    Posted 9 years ago on Friday December 21, 2012 | Permalink
  10. I don't think it should return more than one user. Sounds like it's being called without any parameters, so it just returns everything?

    Posted 9 years ago on Saturday December 22, 2012 | Permalink
  11. theslink2000

    From what I understand of the function you're right, it should only return all if there is no criteria, but as you can see here it is outputting everything:

    Also just to make sure I've tested it with 'login' and 'user_login', both have the same effect.

    Posted 9 years ago on Saturday December 22, 2012 | Permalink
  12. It is returning everything, but that just makes me thing that at the time it's being called, $entry[24] is not returning the correct value. Can you turn on WP_DEBUG and see if there are any warnings or notices being triggered that we're not seeing?

    Posted 9 years ago on Saturday December 22, 2012 | Permalink
  13. theslink2000

    WP_DEBUG is on as the site is still being built, nothing is showing up I'm afraid. If you want access give me an email address and I'll ping the details over.

    I'm totally stumped, the user_login value found in $entry[24] is pre-set by the code (see this pastie from above ) so it can't be wrong, also the structure is appearing in the database properly and you can then login with the information after the form has submitted. Also just to be 100% sure you can dump out $entry[24] and it's correct.

    What else could possibly be stopping it? Or do you have any idea how else I could find the new user's id? I can't think of anything as no other information is guaranteed to be unique (I've got a good reason for disabling unique emails).

    I'm not sure what day's you're working next week but if you get this before Christmas I hope you have a good one bud, and thanks for the continuing help.

    Posted 9 years ago on Sunday December 23, 2012 | Permalink
  14. Please do send me a WordPress administrator login to and I will take a look at it. Please reference this topic when you send the details. Thank you.

    Posted 9 years ago on Monday December 31, 2012 | Permalink