Forums

Contact Form 7
How to: Redirect after submit (1 post)

  1. mawe
    Member
    Posted 3 months ago #

    Just wanted to share how I do my redirects with Contact Form 7 as the official solution to this isn't very satisfying for a number of reasons (especially the dependance on JavaScript).

    I'd love to put this in an already existing thread here, but they're all closed already.

    Anyway! No source hacks involved, it relies on an action added by CF7 itself, no JavaScript needed.

    In your theme's function.php (or in a mini plugin, whatever) add this code:

    add_action('wpcf7_mail_sent', 'ip_wpcf7_mail_sent');
    function ip_wpcf7_mail_sent($wpcf7)
    {
    	$on_sent_ok = $wpcf7->additional_setting('ip_on_sent_ok', false);
    
    	if (is_array($on_sent_ok) && count($on_sent_ok) > 0)
    	{
    		wp_redirect(trim($on_sent_ok[0]));
    		exit;
    	}
    }

    The ip_ is a prefix I'm using. You can change the identifiers if you know your stuff.

    Then, in any CF7 form in the additional settings (at the very bottom), add this:
    ip_on_sent_ok: http://example.com

    Does the trick for me.

Reply

You must log in to post.

About this Plugin

About this Topic