Support

Home Forums Event Espresso Premium Skip Registration Confirmation Page and Redirect to URL instead

Skip Registration Confirmation Page and Redirect to URL instead

Posted: August 31, 2020 at 1:49 pm


mbeede@tracom.com

August 31, 2020 at 1:49 pm

Greetings – EE4: After I select the “Submit” button on the registration form for an event IF there are no errors I would like to skip the Registration Confirmation page completely, and redirect to another URL right away. I already have plugin with a function written to extend the Submit functionality:

function my_custom_submit_action( $spco, $data)
{
error_log(print_r(“Inside my_custom_submit_action”, true));
// Call the web service method to add this registrant to the desired session
$response = registerMaxParticipant();
error_log(print_r($response, true));
if ($response == true) // Errors are handled inside this method
return (true);

// No errors – redirect to the TRACOM Learning website URL
header(“Location: https://tracomlearning.com/“);
}
add_action(‘AHEE__EE_Single_Page_Checkout__process_attendee_information__end’,’my_custom_submit_action’, 10, 2);

But the Registration Confirmation page is still displaying the redirect is not working. Can you help me out with the right way to do this with EE4?

Thanks, Mark


Tony

  • Support Staff

September 1, 2020 at 9:23 am

Hi Mark,

That filter will be ‘fired’ on an ajax request and not the page you are viewing, meaning you won’t see the redirect with the above.

Take a look at how the attendee information reg step does pretty much exactly what you are trying to do HERE.

update_reg_step() runs after process_reg_step() (which is where that hook you mentioned is fired) so the method to do what you are trying to do is pretty similar.


mbeede@tracom.com

September 1, 2020 at 10:26 am

Tony – I am not sure I am following you. I looked at the code snippet. So are you saying that I need to add the code from line numbers 1462 to 1470 to my custom action, or do I need to create a new action/filter for this? I’m a little confused.

Also I just purchased a priority support token. If I use it for this can I get more in-depth (detailed) help or how does that work?

Finally, just curious is Josh no longer on your support staff?

Thanks, Mark


Tony

  • Support Staff

September 1, 2020 at 2:47 pm

Tony – I am not sure I am following you. I looked at the code snippet. So are you saying that I need to add the code from line numbers 1462 to 1470 to my custom action, or do I need to create a new action/filter for this? I’m a little confused.

My apologies, with you extending the above to add your own functionality I assumed you could follow this with minimal details and just needed a nudge in the right direction.

This hook AHEE__EE_Single_Page_Checkout__process_attendee_information__end first on an ajax request, a separate request from the one you see on the page and then returns the values to SPCO.

That hook is fired at the end of the process_reg_step() method, right after that update_reg_step() is run, so you can use that method as a guide on how to redirect the user.

So, this:

header(“Location: https://tracomlearning.com/“);

Can’t be used on the ajax request as it redirects the ajax request, not the user. Instead if we follow what update_reg_step() is doing to SPCO we can swap out the above line for something like:

$spco->checkout->redirect = true;
$spco->checkout->redirect_url = 'https://tracomlearning.com/');
$spco->checkout->json_response->set_redirect_url($spco->checkout->redirect_url);
return true;

SPCO will handle the redirect for you and do what you are trying to do. However, this:

if ($response == true) // Errors are handled inside this method
return (true);

Is going to prevent that from running, if the response is true you’ve already returned before you redirect, so you should use something like:

if ($response == true) { // Errors are handled inside this method
    $spco->checkout->redirect = true;
    $spco->checkout->redirect_url = 'https://tracomlearning.com/');
    $spco->checkout->json_response->set_redirect_url($spco->checkout->redirect_url);
    return true;
}

Also I just purchased a priority support token. If I use it for this can I get more in-depth (detailed) help or how does that work?

Generally, we don’t provide the above level of support for customizations, as we can not support/review your custom code. With a support token we can (if possible within the timeframe ) provide you with a working snippet and explanation like that above.

Its a judgement call in that if you purchase a support token and ask use to completely rewrite X functionality or create a custom some custom output for you etc then we will likely refuse as it simply isn’t viable on both sides to use support tokens. But if you need us to walk fix X and or explain Y we are happy to do so as long as it relates to Event Espresso.

Finally, just curious is Josh no longer on your support staff?

Yes, Josh is still a member of the team 🙂


mbeede@tracom.com

September 1, 2020 at 4:57 pm

So if I swap my line:

header(“Location: https://tracomlearning.com/“);

So for the code that you recommended I need to get a single page checkout object $spco somehow don’t I?
If so do I do this to get it (or something like this?):

$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout )
{
use the object

One more thing: If my web service call results in an error I need to display the error. Normally I would just display it on the Registration Confirmation page, but now I am eliminating that page so I was thinking just use a popup message instead. I tried the easy PHP way to do this:
echo ‘<script language=”javascript”>’;
echo ‘alert(“Test Return Error”)’;
echo ‘</script>’;
But this doesn’t work. No popup window displays at all. Do you know what I can do to display an error if the Registration Confirmation page is not utilized?

Tony – I know some basic PHP but in the past Josh has helped out with a TON with the custom PHP coding I have needed to do in EE. That’s why I asked about him earlier.

Thanks for all of your help and going deeper with your explanation…

Mark


Tony

  • Support Staff

September 2, 2020 at 5:20 am

So for the code that you recommended I need to get a single page checkout object $spco somehow don’t I?

Yes, and you already have all you need.

AHEE__EE_Single_Page_Checkout__process_attendee_information__end is passed the EE_SPCO_Reg_Step_Attendee_Information reg step and $valid_data so your function above, you call back has:

function my_custom_submit_action( $spco, $data)

$spco will be the EE_SPCO_Reg_Step_Attendee_Information instance and $data is the valid data variable from within the class, so the $spco variable can be used here and the code I gave you will work as is.

Did you try using the code I gave you above in your function and then test a registration? This:

function my_custom_submit_action( $spco, $data)
{
	error_log(print_r("Inside my_custom_submit_action", true));
	// Call the web service method to add this registrant to the desired session
	$response = registerMaxParticipant();
	error_log(print_r($response, true));
	// No errors – redirect to the TRACOM Learning website URL
	if ($response == true) { // Errors are handled inside this method
	    $spco->checkout->redirect = true;
	    $spco->checkout->redirect_url = 'https://tracomlearning.com/');
	    $spco->checkout->json_response->set_redirect_url($spco->checkout->redirect_url);
	    return true;
	}
}
add_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end','my_custom_submit_action', 10, 2);

If so do I do this to get it (or something like this?):

$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout )
{
use the object

That gets you an instance of EE_Checkout from the current session, the code above uses the EE_Checkout from within SPCO, you need to use the above for what you are trying to do.

But this doesn’t work. No popup window displays at all. Do you know what I can do to display an error if the Registration Confirmation page is not utilized?

Yeah, that’s not going to work because if you’re using the above its firing on a separate request (the Ajax request in the background).

You could use EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); to add an error on similar to how Event Espresso does.

Have you had a looked into how the process_reg_step() method (where the hook you are using is) shows those errors? If not take a look HERE.

Tony – I know some basic PHP but in the past Josh has helped out with a TON with the custom PHP coding I have needed to do in EE. That’s why I asked about him earlier.

I’m not sure how to reply to this without it coming across the wrong way but if you prefer to wait for Josh I can ask him to take a look at this thread when he has some time. However, I’m not really sure what additional information he can give you without doing it for you as everything you need to do what you have requested is already in this thread.


mbeede@tracom.com

September 2, 2020 at 2:31 pm

Tony – Sorry for that last post in that I didn’t realize my action already had the $spco as an input argument. I just overlooked it. I’m more tired than I thought I guess. And by my last comment I only meant that the reason it might have appeared that I am more knowledgable about EE than I really am is that I have received a lot of help from Josh in the past to get most of my code setup. I didn’t do it myself. I wasn’t implying that I wanted him now for this. You have been really helpful and I really appreciate it – I’m trying all this code out now…


mbeede@tracom.com

September 2, 2020 at 4:23 pm

So I tried this new code out. The good news is a redirect is occurring. The bad news is it is redirecting to my WordPress Admin login page and not to the tracomlearning.com page. I tried http, https, various different flavors of that URL, and I tried just google.com. I keep going to this URL:

https://tracomtrainstg.wpengine.com/wp-login.php?redirect_to=https%3A%2F%2Ftracomtrainstg.wpengine.com%2Fwp-admin%2F&reauth=1#checkout

I debugged the checkout object and it looks like the right values are being set in the object itself so I am not sure why it’s going to this other URL. Is there a default redirect URL that is set at some point in EE, maybe in the settings?
Any quick ideas?

Thanks for your help – Mark


Tony

  • Support Staff

September 2, 2020 at 4:51 pm

Actually it is using wp_safe_redirect() so you’ll likely need to whitelist that domain for it to work, you can do that using a snippet like this:

https://codex.wordpress.org/Plugin_API/Filter_Reference/allowed_redirect_hosts

And you would have something like:

$content[] = 'tracomlearning.com';


mbeede@tracom.com

September 3, 2020 at 8:27 pm

Tony – Thanks for the redirect information. Now the redirect is working great. Also thanks for the error related information. I put that code into place but really strange things were happening. Long story short I found out that my theme is conflicting with EE in some places. When I switched to the standard 2019 WordPress theme everything worked exactly like it should. So I have some work to do on the theme to see why it is conflicting with Event Expresso on form and error processing.

THANK YOU VERY MUCH for all your help – I really appreciate it!

Mark


Tony

  • Support Staff

September 4, 2020 at 2:04 am

You’re most welcome.

I’m guessing the conflict is based around the espresso-notices and/or espresso-ajax-notices?


mbeede@tracom.com

September 10, 2020 at 12:58 pm

I spoke too soon – I still have a redirect issue, let me show you…
Go to this URL: https://tracomtrainstg.wpengine.com/sessions/ey-americas-social-style-multi-rater. Click the Register Now button.

On the Register Form fill in the first 4 fields with whatever (make sure the 2 email addresses match). On the Access Code field enter “Test”. Check the box and select the Submit Registration button. SO if that Access Code had been valid then EE would go straight to the redirect like it’s supposed to.

But this Access Code is invalid so it will throw an error. Dismiss the error box and change the Access Code to “EYAccessCode” which IS valid. Select the Submit Registration button again. Now EE displays the Thank You page instead of going to the redirect URL, which I don’t want.

So throwing that error is causing some condition to be set in EE so that it behaves differently on the next submit. Do you have any idea how to resolve this so that it correctly goes to the redirect URL instead?

Thanks again in advance – Mark


mbeede@tracom.com

September 14, 2020 at 8:58 am

Tony – I should have also mentioned that in my PHP code once I determine that the Access Codes do NOT match I throw an error using the statement that you suggested further up in this posting:

EE_Error::add_error(esc_html__($error, ‘event_espresso’), __FILE__, __FUNCTION__, __LINE__ );

Hope that helps with this…

Thanks, Mark


Tony

  • Support Staff

October 7, 2020 at 8:02 am

Hi Mark,

Just noting here for future readers that this issue was resolved via email and a new filter will be added to Event Espresso which allows you to hook in before the reg step is processed and prevent the registration.

The issue above is happening because the current hook runs after the registration has been processed and all of the registration questions have been saved etc. The submission is halted and then resubmitted with the correct code, but now EE knows there are registration answers and its trying to compare the form with the saved values (which is should be doing) and things get confused.

Adding a new hook into this allows you to hook and stop the process before that happens, throw an error and only submit when it actually should do.

The support post ‘Skip Registration Confirmation Page and Redirect to URL instead’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso