Passing User Messages to Another Page

I’ve got a form that does a fair bit of processing. Along the way, things may not work out as expected, and I want to display messages to the user. I’ve got that working.

However, if things go well, I also want to let the user know. But here’s where it gets dicey: I want to go to the custom login page (via wp_redirect()) and display the message there. So, how do I send the message to the login page?

I’ve dreamed up a pretty involved mechanism, that may work. But I figure this is a fairly standard pattern: WP must already have something in place for this sort of thing.

1 Answer
1

A standard approach is to add a query parameter to the location header (redirect), for example:

$redirect = add_query_arg( 'my-form', 'success', $redirect );
wp_redirect( $redirect );
exit;

Then on the redirected-to page, you can conditionally display a message:

<?php if ( filter_input( INPUT_GET, 'my-form' ) === 'success' ) : ?>

    Congrats!

<?php endif ?>

Leave a Comment