• Hi.
    Our Gravity form (using your plugin) submits registration to a remote site. If you enter an existing email address, the remote site throws an error : “User already exists” .. but it happens in the html of the page, and not as a direct return variable. I see the message in the debug “RESPONSE” array, along with the entire HTML of the page it is shown on.

    We’d like to somehow capture this error from the remote site and show it to the user when they submit the form, so they can resubmit the form again with a unique email address.

    Is this possible with hooks? If so, can you mock up an example of how to implement this?

    Thanks

    https://ww.wp.xz.cn/plugins/forms-3rdparty-integration/

Viewing 1 replies (of 1 total)
  • Thread Starter e dev

    (@efishinsea)

    So, just an update, but still in need of a solution, I have created a callback to catch the error from response, and I am now getting an email sent to me from this error,

    **RAW RESPONSE**
    Array
    (
        [reason] => Service Callback Failure
        [safe_message] => Service Callback Failure
        [errors] => Array
            (
                [0] => Account or Email address already exists.  Please try again.
            )
    
    )

    but the error is never shown to the user, and the form submits as if everything is ok.

    Here is what I am using currently:

    if(!class_exists('Cf73rdParty_ExistingCallbacks')):
    
    	// Encapsulate any and all 3rd-party service callback functions
    	class Cf73rdParty_ExistingCallbacks {
    
    		public function __construct(){
    			add_action('Forms3rdPartyIntegration_service_a0', array(&$this, 'check_for_existing_callback'), 10, 2);
    		}//--	function __construct
    
    		public function check_for_existing_callback($response, $results){
    			try {
    
    				if( false !== strpos($response, 'already exists')  )  {
    					$output = 'Account or Email address already exists.  Please try again.';
    
    					// set return results - text to attach to the end of the error
    					$results['errors'] = $output;
    					$results['message'] = $output;
     					//throw new Exception($output);
     					//die;
    				}
    
    			} catch(Exception $ex){
    				// indicate failure by adding errors as an array
    				$results['errors'] = array($ex->getMessage());
    			}
    		}
    	}//---	class Cf73rdParty_ExistingCallbacks
    
    	//start 'em up
    	$cf73rdpartycallback_instance = new Cf73rdParty_ExistingCallbacks();
    
    endif;	//class-exists

    What I need is to push this error back to the form so that it stops the submit and informs the user. Any insight would be appreciated.

Viewing 1 replies (of 1 total)

The topic ‘catch error message from response body’ is closed to new replies.