• 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: https://example.com

    Does the trick for me.

Viewing 7 replies - 16 through 22 (of 22 total)
  • Thread Starter maryisdead

    (@mawe)

    Looks fine to me. Any errors shown?

    No just a white page on all the website online and “wp_redirect” or “Location” doesn’t work on local..

    Thread Starter maryisdead

    (@mawe)

    Just tried the exact same code here, works like a charme.

    If you just get a blank page, you should figure out where your error logs are and see what the problem is.

    It’s working perfectly now.. Maybe I was tired yesterday. Thank you very much for all.

    Thread Starter maryisdead

    (@mawe)

    Glad to hear you got it working!

    Great, brilliant, superb. Seriously, that was awesome! A million thanks. I’ve been all night looking for a hack like this.

    I’m using Contact Form 7 on a jQuery Nyromodal popup and I wasn’t able to redirect to an specific page after clicking send. The problem was that when I clicked send I was always being redirect to the .php page (which incluedes de CF7) that I loaded with Nyromodal.

    By the moment this hack -targeting a desired page- is a good way to solve that problem. But…

    Does anyone know how to make Contact Form 7 working in a jQuery pop up window without any kind of redirection?

    Thanks

    I’d like to move from a form submission to another page based on the post category, but can’t seem to get this to work within the funcitons.php page. I have multiple pages using the same contact form, and each is tagged with a category. Based on which page they submit the form from, I want to redirect them to a category-specific “next” page. Here’s the code I have – any suggestions would be appreciated!

    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);
    
    	global $wp_query;
    	$post = $wp_query->post;
    	$category = get_the_category($post->ID);
    	$thisCatName = $category[0]->category_nicename;
    	$redirectPage = "next-" . $thisCatName . ".html";
    
    	if (is_array($on_sent_ok) && count($on_sent_ok) > 0)
    	{
    		wp_redirect(trim($redirectPage));
    		exit;
    	}
    }
Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘[Plugin: Contact Form 7] How to: Redirect after submit’ is closed to new replies.