0

I have a WordPress site that uses ajax to submit a form on the Front-end.

When the form is submitted by a logged-in user, all works fine. When the form is submitted by not-logged-in user, I get a "Bad Request" error.

Here is my code:

JS:

$('form').on('submit', function (e) {
    e.preventDefault();

    // Submit the POST request
    $.ajax({
        url: jsobject.ajaxurl,
        method: 'POST',
        data: {
            action: 'fe_submit_form'
        }
    });
});

PHP:

function fe_submit_form() {
    ...
}
add_action( 'wp_ajax_fe_submit_form', 'fe_submit_form' );

When the user is logged in, all works fine. When the user is not logged it, I never go inside of the "fe_submit_form" php function.

Any ideas?

1
0

The action for non-logged in users is wp_ajax_nopriv_{$action}.

Not the answer you're looking for? Browse other questions tagged or ask your own question.