• Resolved pramilaniroshan

    (@pramilaniroshan)


    Hi,

    Is there any way to show the backend API response in our WordPress UI/contact form7 Page as a modal or toast?

    I saw that u guys use “wpcf7_mail_sent” hook. is it possible to use “wpcf7_before_send_mail” hook and stop the form submitting if any errors occurred in backed. Because we’re using email validation part in backed because it’s lot affected to user experience.

    kindly let me know if we can do that.

    Thanks,

    Pramila.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Mayur Prajapati

    (@mayur8991)

    Hello @pramilaniroshan

    Thanks for using our plugin

    You can modified our plugin action little bit

    open the plugin directory
    contact-form-to-any-api\includes\class-cf7-to-any-api.php
    Line number 169

    instead of

    $this->loader->add_action('wpcf7_mail_sent',$plugin_admin,'cf7_to_any_api_send_data_to_api');
    
    Replace with 
    
    $this->loader->add_action('wpcf7_before_send_mail',$plugin_admin,'cf7_to_any_api_send_data_to_api');

    Hope it helps
    Thanks

    Thread Starter pramilaniroshan

    (@pramilaniroshan)

    @mayur8991 Thanks for the reply. I saw that we can change the plugin action.but my question is can we stop submitting the form and display the backend error message when backend/spring boot app throw an error?

    Thanks.

    Plugin Contributor Mayur Prajapati

    (@mayur8991)

    Hello @pramilaniroshan

    At the moment it Is not possible to manage API side errors to display on cf7 forms like validation messages on frontend

    The api logs which is displaying in backend created after form successfully submitted

    Thanks




    Thread Starter pramilaniroshan

    (@pramilaniroshan)

    Hi @mayur8991 ,

    we can do something like this. we can add a “wpcf7_display_message” filter if our back-end conditions are met.

    class-cf7-to-any-api.php -> line number 169

    $this->loader->add_action('wpcf7_before_send_mail',$plugin_admin,'cf7_to_any_api_send_data_to_api');

    class-cf7-to-any-api-admin.php > add this after line number 634

    if($result) {
    $api_response = json_decode( $result, true );
             if(in_array("400", $api_response)){
                  add_filter('wpcf7_display_message', 'change_submission_msg',10,2);
          function change_submission_msg($message, $status){
            if('mail_sent_ok' == $status){
             $message= 'We are unable to proceed with your request. Because the email address you entered is already on our server - so you probably have an account with us.';
            }
            return $message;
          }
             }

    using that we can manage API side errors to display on cf7 forms like validation messages on fronted.

    Thanks,

    Pramila.

    Plugin Contributor Mayur Prajapati

    (@mayur8991)

    Hello @pramilaniroshan
    Thank you for your valuable suggestion
    But at the moment we have no plan to include such validation in our plugin

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show Back end response in WordPress UI’ is closed to new replies.