Contact-Form-7: 3rd-Party Integration
[resolved] Can i submit the form after the third party script r (2 posts)

  1. abhishekjha
    Posted 3 years ago #

    Can i change it to submit the form only after the third party script reports a success.


  2. zaus
    Plugin Author

    Posted 3 years ago #

    I just added a hook you can use if the service returns a fail response -- see http://wordpress.org/extend/plugins/contact-form-7-3rd-party-integration/other_notes/#Hooks. You can use this to check if there was a problem and update the message accordingly.

    Unfortunately I couldn't really find an easy way to alter the success style (i.e. not green box) - you could try some trickery like this:

    function mycf7_fail(&$cf7, $service, $response) {
    	$cf7->skip_mail = true;
    	// hijack message to well to notify user
    	///TODO: how to modify the "mail_sent" variable so the message isn't green?  on_sent_ok hack?
    	$cf7->messages['mail_sent_ok'] = 'Could not complete mail request: ' . $response['safe_message'];
    	// save to a "persistant" variable so we can use it in later hook
    	global $abt_cf7_mailnotsent;
    	$abt_cf7_mailnotsent = true;
    add_action('Cf73rdPartyIntegration_onfailure', 'mycf7_fail', 10, 3);
    function mycf7_fail_json_echo($items, $result = null) {
    	// use our "persistant" variable from before
    	global $abt_cf7_mailnotsent;
    	if( isset($abt_cf7_mailnotsent) && true === $abt_cf7_mailnotsent ) :
    		$items['mailSent'] = false;
    		$items['invalids'] []= array(
    							'into' => 'span.wpcf7-form-control-wrap',
    							'message' => 'Mail was stopped due to service failure.' );
    	return $items;
    add_filter('wpcf7_ajax_json_echo', 'mycf7_fail_json_echo');

    That is for the ajax submission - for the nonajax (plain post), I think you'd have to alter the $_POST variables that were set in wpcf7_submit_nonajax by hooking later in the init action (12) and using your "persistant variable" to check.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact-Form-7: 3rd-Party Integration
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic