admin管理员组

文章数量:1122832

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 months ago.

Improve this question

I want to integrate custom logic after submit form.

I want to store contact form data in the custom table, if data is stored then the response would be true otherwise false.

I am using wpcf7_before_send_mail hook

Please help me how can I do this.

My sample code here

function save_data_to_project_after_form_submit( $contact_form ) {

// Save data to my custom table

if(data save to database){
  // Same as currently working and mail send
} else {
  // giving error message something went wrong and mail should be not send.
}

} add_action( 'wpcf7_before_send_mail', 'save_data_to_project_after_form_submit', 10, 1 );

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 months ago.

Improve this question

I want to integrate custom logic after submit form.

I want to store contact form data in the custom table, if data is stored then the response would be true otherwise false.

I am using wpcf7_before_send_mail hook

Please help me how can I do this.

My sample code here

function save_data_to_project_after_form_submit( $contact_form ) {

// Save data to my custom table

if(data save to database){
  // Same as currently working and mail send
} else {
  // giving error message something went wrong and mail should be not send.
}

} add_action( 'wpcf7_before_send_mail', 'save_data_to_project_after_form_submit', 10, 1 );

Share Improve this question edited Jun 14, 2018 at 7:37 vishal patel asked Jun 13, 2018 at 9:55 vishal patelvishal patel 1012 bronze badges 3
  • 1 I am not sure to understand, on which condition you don't want to store data ? to store all forms, you can use that contactform7.com/save-submitted-messages-with-flamingo – mmm Commented Jun 13, 2018 at 9:58
  • Try to ALWAYS include your code. How can we help you if we can't see what you have tried? Also, if you only want to store the data, use Flamingo like @mmm commented. – Bjorn Commented Jun 13, 2018 at 11:36
  • I have updated my code. – vishal patel Commented Jun 14, 2018 at 7:37
Add a comment  | 

1 Answer 1

Reset to default 1

Little late to the party (5 years...) but for future generations stumbling upon this question, you can use &$abort in wpcf7_before_send_mail hook to prevent mail from sending:

add_action('wpcf7_before_send_mail','your_function',10,3);

function collect_email($wpcf7_data, &$abort, $object){ //pass reference
    /* your code here */
    if($data_saved == true){
        $object->set_response("Data saved");
    }
    else {
        $abort = true;
        $object->set_response("Data not saved");
    }
}

If you want to have even more control over ajax response, you can use feedback filter:

add_filter('wpcf7_feedback_response', function( $response){
    /* do your stuff with $response array */
    return $response;
});

本文标签: customizationContact form 7 ajax response truefalse based on some condtion