WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

closed as off-topic by birgire, toscho Jul 26 '14 at 9:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the 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

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 ){

            $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. – SachinGutte Aug 20 '13 at 15:39

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