• sheikwor

    (@sheikwor)


    Hi,
    I want to specify whether the request to the web service will be treated as correct or not depending on the service response and therefore make contact 7 show the message in green or in red, but it’s not working. It always is shown in red.

    Among the fields sent to the web service we include the user email.

    The web service returns always the http code 200, but the response text is a JSON that informs whether the user email has already been sent before.

    What I want to do is make the contact 7 form show an error message IN RED if the mail exists, or otherwise redirect the user to a thank you page.

    I am being able to change the default success message by the error message, but it is always shown as a success message.

    Also since I’m not being able to change the contact 7 behavior by changing the action’s $results[“success”] to false, I’m not being able to use some contact 7 native hook to redirect the user to a thank you page in case of success or stay in the current page in case of error (in my case, the user email has already been submitted).

    Here I post the code in functions.php:

    
    add_action('Forms3rdPartyIntegration_service_a1', 'show_error_if_mail_exists', 10, 2);
    
    function show_error_if_mail_exists($response, &$results){
    	$rsp = json_decode($response);
    	if ($rsp->api_status == 501) { //The user mail is already registered
    		$results["success"] = false;
    		$results["message"] = "The email address is already in the system."; 
    	}
    }
    

    The error message IS actually shown in Contact 7, but as a success message (in green) instead of an error message (in red).

    IMPORTANT: if the web service response text does not say ‘501’, then I need to redirect the user to a different thank you page (URL). If it is ‘501’, then I should show the error message in red.

    Thanks in advance,

    Adrián

  • The topic ‘Set ‘success’ to false in action Forms3rdPartyIntegration_service_a1 not working’ is closed to new replies.