Skip Navigation

[Résolu] Success message on redirect page after form submission

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I would like to redirect to the homepage after submitting a Form, and I would like to display a success message there.

Solution: You could append a special URL parameter to the redirection URL, then use conditional HTML on your homepage template to display a notice. To append a URL parameter to the redirection URL, you must set up the Form to redirect to some page. It doesn't matter which page, we will override that in code.

function tssupp_delete_user_redirect( $url, $post_id, $form_data ){
 
    if ( 123 == $form_data['id'] ) {
 
        $url = 'https://yoursite.com/?user-deleted=1';
    }
 
    return $url;
}
add_action( 'cred_success_redirect', 'tssupp_delete_user_redirect', 10, 3 );

Replace 123 with the numeric ID of the delete User Form.

Your visitor will be redirected to the homepage with the URL parameter added. Then in your homepage template you can display the message using conditional HTML:

[wpv-conditional if="( '[wpv-search-term param="user-deleted"]' eq '1' )"]
Your account has been deleted.
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/

This support ticket is created Il y a 5 années et 8 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par diyanK Il y a 5 années et 8 mois.

Assisté par: Christian Cox.

Auteur
Publications
#1223581

Hi team,

I'm trying to create fully functional delete (self) account feature on my project and I need a little help.

I started with the guide from this ticket:
https://toolset.com/forums/topic/add-the-link-delete-account/#post-1223439

The method works and deletes the custom user and his custom posts. Also how about a working confirmation msg that shows on the homepage once the user gets redirected back to it after deletion?

Thanks in advance!
Diyan

#1223598

You could append a special URL parameter to the redirection URL, then use conditional HTML on your homepage template to display a notice. To append a URL parameter to the redirection URL, you must set up the Form to redirect to some page. It doesn't matter which page, we will override that in code.

function tssupp_delete_user_redirect( $url, $post_id, $form_data ){

    if ( 123 == $form_data['id'] ) {

        $url = '<em><u>lien caché</u></em>';
    }

    return $url;
}
add_action( 'cred_success_redirect', 'tssupp_delete_user_redirect', 10, 3 );

Replace 123 with the numeric ID of the delete User Form.

Your visitor will be redirected to the homepage with the URL parameter added. Then in your homepage template you can display the message using conditional HTML:

[wpv-conditional if="( '[wpv-search-term param="user-deleted"]' eq '1' )"]
Your account has been deleted.
[/wpv-conditional]
#1223624

Worked like a charm!

I didn't know we can use conditionals this way, this is a very nice feature with a great potential for use in my projects.

Also I wrapped the alert in these:

<div class="alert alert-danger alert-dismissible" role="alert">Your account has been deleted.</div>