Make “input” field required

  • Author
    Posts
  • adminplantzeebo

    In the settings option under my account, i want to make the entries under it “required” instead of optional and also redirect a new user who has registered to the settings page/form.

    ihordeveloper

    If you mean the first name, last name and description fields you can make them required by overriding their settings via HivePress API “hivepress/v1/forms/user_update” filter, here’s an example:

    add_filter(
    	'hivepress/v1/forms/user_update',
    	function( $form ) {
    		if ( isset( $form['fields']['first_name'] ) ) {
    			$form['fields']['first_name']['required'] = true;
    		}
    
    		return $form;
    	},
    	1000
    );

    But there’s no way to force users to set these details, they can still register.

    adminplantzeebo

    Do i need to make these cahnges under includes/models/class-user.php:100 file ?

    ihordeveloper

    Please don’t edit the plugin files directly, any changes will be erased on update. You can try using this plugin to manage custom PHP snippets https://wordpress.org/plugins/code-snippets/ or create a child theme and put it in functions.php file.

    adminplantzeebo

    Hi, I have used code snippets plugin to make the above code snippet to work , it works perfectly. However is their some changes i can make to the php files of Hivepress to direct a newly registered user directly to the Settings option under My account. ?

    adminplantzeebo

    If the above is not possible, how can i add additional fields to the register form ?
    I just need to add the name as well as the contact number fields
    Thank you.

    ihordeveloper

    Please check this topic for setting a custom redirect (there’s a code snippet) https://hivepress.io/support/topic/registration-page-with-block-editor/#post-4677 Adding custom fields to the registration form requires more customizations, because they should be also saved somehow, not just added so there’s no simple snippet for this.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.