Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am creating a Website in WordPress using Contact Form 7. In my site I have several documents on different pages. In order to access those documents, first the user has to fill out a form and then he/she will receive a mail with a link to access that PDF.
My Question is - how can I redirect the form after successful submission to the original page and please remember that I have different pages and all of them are using the same form...

share|improve this question

3 Answers 3

In Contact Form 7 below each form there would be an Additional Settings metabox. You could redirect the form to a particular page after successful submission by putting the following in the Additional Settings metabox.

on_sent_ok: "location = 'http://example.com/thank-you/';"
share|improve this answer
Thanks for your reply Joshua but I have tried this and the problem while using this is that It redirects to a particular page and as I want that the form should redirect to different pages based clicking on the links that are on different pages. –  Shivali Jan 8 '13 at 9:54

The way I do this on a few client sides is adding a Javascript function and referencing this in the settings metabox like this:

on_sent_ok: "wpcf7GotoSluggedUri('/my-base-url');"

And then I add this JS function to the themes_header. This could include any logic you want like history.back() to go to the page visited before or something based on the current URL like in the following example:

function wpcf7GotoSluggedUri(uri) {
    var cur_uri = document.location.pathname.split('/'),
    slug_array = new Array('slug-1', 'slug-2', 'slug-3');

    if( jQuery.inArray(cur_uri[1], slug_array) > -1 ) {
        document.location = '/' + cur_uri[1] + uri;

You could also easily use this to pass a value generated in PHP:

function wpcf7GotoSluggedUri() {
    document.location = '<?php echo $theValueFromPHP; ?>';

But be aware that the whole "on_sent_ok" stuff only works on AJAX submit. If JS is disabled and the form is submitted via $_POST the redirect doesn't work.

share|improve this answer

Why not get the attachment directly, create the email, then send it all at once without the redirection. Contact Form 7 has a before mail send function:

function send_pdf( $cf7Obj ){
    global $post;

    if($post->ID == 123){
        $cf7Obj->uploaded_files = array('pdf' => $pdf_file_path);
add_action( 'wpcf7_before_send_mail', 'send_pdf' );

You would need to get the file path for the PDF. It's a pretty powerful function - you can check out the docs here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.