• Hi guys,

    Quick one: how to handle AJAX for submission failures?

    If it fails, it shows no message and just keeps spinning/the form and button are disabled. We need a way to customise the response, such as saying that they should reach out to support and potentially also show the error message.

    It would be good to allow form to be resubmitted too, in case they can modify the submission and get it to pass with or without our help.

    Keep up the great work on this plugin.

    Thanks,
    Theo

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author philkurth

    (@philkurth)

    Hi Theo,

    Can you tell me a bit more about what you are experiencing by way of failure? The AJAX related JS has an error handler so if the server sends an error code, something should happen.

    It sounds as though perhaps there is a network issue or something the is stopping execution of the JavaScript. When this happens, are there any exceptions in the browser console? Additionally, are there any errors on the server?

    Is there possible a site set up that reproduces the issue so that I can take a look?

    Cheers,
    Phil

    Thread Starter Theo Pape

    (@theo38)

    Hi Phil,

    I noticed this when there was a PHP fatal error in one of my project’s files:

    PHP Fatal error: Uncaught TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in …/form-actions.php:407

    wp-admin/admin-ajax.php:1

       Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    forms.js?ver=1.9.1:1 Uncaught TypeError: Cannot read properties of undefined (reading ‘data’)
    at Object.error (forms.js?ver=1.9.1:1:4106)
    at c (jquery.min.js?ver=3.7.1:2:25304)
    at Object.fireWith as rejectWith
    at l (jquery.min.js?ver=3.7.1:2:77807)
    at XMLHttpRequest. (jquery.min.js?ver=3.7.1:2:80265)

    Points to this:

        onError: function(t) {
            return function(e) {
                var a = t.$el.data("acf")
                  , e = e.responseJSON.data.errors;
                a.addErrors(e),
                a.showErrors()
            }
        }

    Hope that helps. Would be useful if you could provide some way to hook into this ^^

    Plugin Author philkurth

    (@philkurth)

    Hi Theo,

    What is the full path to the form-actions.php file?

    Thread Starter Theo Pape

    (@theo38)

    I don’t really want to start sharing that. But it’s included in functions.php. So you could just add a similar line of code there.

    Thread Starter Theo Pape

    (@theo38)

    add_action( ‘profile_update’, ‘profile_update_function’, 10, 1 );

    Is where the code comes from that is causing the error.

    Plugin Author philkurth

    (@philkurth)

    Thanks Theo,

    I can’t find that line of code in the plugin. I’ll need more context here. Is it possibly a different plugin that is causing the issue?

    Cheers,
    Phil

    Thread Starter Theo Pape

    (@theo38)

    Sorry Phil, I’m not being clear enough. Try this:

    Make a form that updates user details.

    Inside functions.php add the add_action( ‘profile_update’, ‘profile_update_function’, 10, 1 );

    Inside this function, cause a PHP fatal error, such as array_search on a null value. This should then cause the AJAX to fail and the form to freeze with no output/explanation to the user.

    Plugin Author philkurth

    (@philkurth)

    Thanks Theo,

    I’ll spend some time with this and see if there’s anything I can do in the way of a patch release over the next week or so. I’ll write back here with what I find.

    Cheers,
    Phil

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Handle AJAX failures’ is closed to new replies.