How to prevent user from updating if field isn’t filled out

[ad_1]

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]
2 Comments
  1. >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.

  2. 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])

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer