I’m trying to stop the default action of the ‘Update User’ button in the admin panel if there are required fields that aren’t filled out. Right now this is what I’m doing:
function require_shipping_info() {
if(empty($_POST[‘shipping_phone’]) || empty($_POST[‘shipping_address_1’])) {
wp_die(_(‘Error: Please make sure that the shipping address and phone number are filled out’));
}
}
add_action(‘user_register’, ‘require_shipping_info’);
add_action(‘profile_update’, ‘require_shipping_info’);
However, I’d prefer if I could just prevent the page from even being reloaded and just give a notification using the `admin_notices` hook.
[ad_2]
>However, I’d prefer if I could just prevent the page from even being reloaded
Then you’d use JavaScript to handle this instead of PHP.
You need front-end validation. It’s not hard to [write your own]) especially with only a few fields to manage, but you can get more elaborate with libraries like [validate.js])