Using hook WPCF7_before_send_mail in my own plugin, but form is not resetting.
-
Hello. I hope someone is able to solve this issue with me. I have written a custom plugin that hooks CF7 using the wpcf7_before_send_mail hook, retrieves the form data, and then uses cURL to POST to our Salesforce “Web-to-Case” system.
The plugin does everything correctly except one thing. The form just “hangs” and does not reset the form after submission. I feel like my plugin is interrupting the AJAX code to reset the form, but I am lost on finding a solution.
Here is the URL: https://www.magicinkjet.com/products/dmibop/ (You need to click the “Request a Sample” button on the left of the page to open the form.)
Here is my plugin code (I’ve removed sensitive data in my code.):
add_action( 'wpcf7_before_send_mail', 'web_to_salesforce' ); function web_to_salesforce($cf7) { $submission = WPCF7_Submission :: get_instance() ; $wpcf = WPCF7_ContactForm :: get_current() ; if( $wpcf->id == 47 ){ // 47 being the id of the CF7 form if (!$submission) { return false; } //$mail = $wpcf->prop('mail'); $posted_data = $submission->get_posted_data() ; // assign CF7 fields to PHP data variables $url = 'https://webto.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8'; $fields = array( 'debug' => 1, // set to 1 to active debug mode 'debugEmail' => '[email protected]', 'orgid' => '0xxxxxxxxxxxxxx', 'recordType' => $posted_data['Case-Record-Type-ID'], 'subject' => $posted_data['subject'], '0xxxxxxxxxxxxxx' => $posted_data['brand'], '0xxxxxxxxxxxxxx' => $posted_data['referral-source'], 'priority' => $posted_data['priority'], '0xxxxxxxxxxxxxx' => $posted_data['product-name'], '0xxxxxxxxxxxxxx' => $posted_data['company'], '0xxxxxxxxxxxxxx' => $posted_data['first-name'], '0xxxxxxxxxxxxxx' => $posted_data['last-name'], '0xxxxxxxxxxxxxx' => $posted_data['title'], '0xxxxxxxxxxxxxx' => $posted_data['phone'], '0xxxxxxxxxxxxxx' => $posted_data['email'], 'email' => $posted_data['email'], '0xxxxxxxxxxxxxx' => $posted_data['dealer'][0], '0xxxxxxxxxxxxxx' => $posted_data['Have-a-dealer'][0], '0xxxxxxxxxxxxxx' => $posted_data['address1'], '0xxxxxxxxxxxxxx' => $posted_data['address2'], '0xxxxxxxxxxxxxx' => $posted_data['city'], '0xxxxxxxxxxxxxx' => $posted_data['state'][0], '0xxxxxxxxxxxxxx' => $posted_data['zip'], '0xxxxxxxxxxxxxx' => $posted_data['Country'][0], '0xxxxxxxxxxxxxx' => $posted_data['Province'][0], 'submit' => 'Submit' ); curl_send_to_salesforce($url, $fields); return $cf7; } } function curl_send_to_salesforce($url, $fields){ // URL-ify the data for the POST $fields_string = http_build_query($fields); // Open connection $ch = curl_init(); // Set the url // Set the number of POST vars // Set the POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Connection: keep-alive', 'Cache-Control: max-age=0', 'Upgrade-Insecure-Requests: 1', 'Origin: https://www.magicinkjet.com', 'Content-Type: application/x-www-form-urlencoded', 'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Sec-Fetch-Site: cross-site', 'Sec-Fetch-Mode: navigate', 'Sec-Fetch-User: ?1', 'Sec-Fetch-Dest: document', 'Referer:https://www.magicinkjet.com', 'Accept-Language: en-US,en;q=0.9' )); curl_setopt($ch, CURLOPT_FAILONERROR, true); // Required for HTTP error codes to be reported via our call to curl_error($ch) curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Set data to be posted //curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); // Execute post $result = curl_exec($ch); // Close connection curl_close($ch); return $result; }
Any assistance would be greatly appreciated! I’ve spent almost a week troubleshooting this issue and I haven’t found a solution.
The page I need help with: [log in to see the link]
- The topic ‘Using hook WPCF7_before_send_mail in my own plugin, but form is not resetting.’ is closed to new replies.