Form submission in WordPress front end

You have multiple way yo handle form submition, one of those is a post action.

But first you need to create the proper form attributes and tags for it to work, so it should look something like this.

HTML

<form action="<?= esc_url(admin_url('admin-post.php')); ?>" method="post">
    <!-- this will "indicte" to the hook that will handle the submition -->
    <input type="hidden" name="action" value="action_my_hook_name">
    <!-- if needed you can add a nonce for security -->
    <input type="hidden" name="security" value="<?= wp_create_nonce('my_form_nonce'); ?>">

    <input type="text" name="first_name" />
    <input type="text" name="last_name" />
    <input type="submit" value="Submit">
</form>

PHP (in functions.php)

add_action('admin_post_action_my_hook_name', 'action_my_hook_name'); // logged in users
add_action('admin_post_nopriv_action_my_hook_name', 'action_my_hook_name'); // not logged in users

function action_my_hook_name () {
    // checking if nonce was submited and is valid, if not valid will exit
    check_ajax_referer('bt_site_nonce', 'security');

    // handle form submition
}

error code: 523