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 new to wordpress and I am trying to create a simple form. I am currently using contact form 7 and so far it find it nice. But now, I am trying to execute a server side code when the form is submitted. Basically, what I just want is to get the post variables from the from when it is submitted so that I can use the form data in the script. I still want the email functionality that sends to the email address when the form is submitted.

Is there a simple and more efficient way to do it without me need to change anything in the code?

share|improve this question
    
Define "server side script"? Are you talking about PHP that can run in a WordPress context? A bash/Perl/other script? What? And what does the script need to do? –  s_ha_dum Aug 20 '13 at 4:51
add comment

1 Answer

You need wpcf7_before_send_mail hook that gets triggered after sending email successfully. Just add this in your functions.php.

add_action( 'wpcf7_before_send_mail', 'process_contact_form_data' );
function process_contact_form_data( $contact_data ){

    var_dump($contact_data->posted_data);
            $name = $contact_data->posted_data["your-name"];
    $email = $contact_data->posted_data["your-email"];

    echo $name ;
    echo $email;                
}

You can access fields by their name in $contact_data->posted_data array.


Yes. You can redirect to another page either with javascript or from above function. With javascript you need to add following line in Additional Settings of contact form you've created.

on_sent_ok: "location = 'http://youdomain.com/thankyou.php';"

But this won't allow you to use values sent from form. So go for alternate method.

Redirect to thankyou page from above mentioned function. But before redirecting, set information you want to show on thankyou page into SESSION variables ( like name, email, subject fields from form ). Then on thankyou page, get those values and display them. Later you can destory session variables and check everytime if those certain variables are set. This will give control over hitting thankyou url directly from browser and show appropriate message saying page is not directly accessible.

share|improve this answer
    
Thanks for your reply @Phobos. Is it possible that when the form has been submitted then I will redirect to something like a thank you page wherein I could use the post variables from the form that was just submitted from contact 7? –  drifter Aug 20 '13 at 12:58
    
@drifter please check updated answer. –  SachinG Aug 20 '13 at 15:39
add comment

Your Answer

 
discard

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.