Create custom User Settings page form

Hi, can anyone assist with how to create a custom form with only email, current password and new password fields? I would like to use it in a custom user account Security Settings Page for security settings separate from the user_update form.

I tried to replicate the user_update form based on the Model_Form class and user controller files using a custom plugin but the field input data is not saved and the form is cleared up when the page is reloaded.

Hi,

Unfortunately, there is no simple solution here, as this form should not require the current password, and the email cannot be edited without confirmation like a regular field. That is, to set this up correctly, you need a custom form, an action where the form will send the request, and you need to add the appropriate custom logic there. We recommend that you check out the GitHub to see how this form is made and the action itself: hivepress/includes/controllers/class-user.php at master · hivepress/hivepress · GitHub. Also, you can do this without necessarily using HivePress, as we use the WP Users API, so you can do it the way you want (through a third-party plugin or other custom implementation).

​I hope this is helpful to you.

Yes, I modified this very function:

public function update_user( $request ) {
	}

Where I’m able to get my submitted custom form array data here:

$form->set_values( $request->get_params() );

But not saved even after getting a Settings saved notification here:

$user->fill( $form->get_values() );

So was wondering if there’s a step I’m missing that prevents the form data from being saved even after getting a success message.

Hi, I managed to get it working. Just one more thing, is there a code to conditionally add an attribute to only one specific form? I’m using this filter: hivepress/v1/models/user/attributes

Hi,

Unfortunately, there is no such possibility since there is only one editable function and those that inherit it. Please note that if you edit the theme files directly, any update from our side will delete all your changes, so I recommend using this doc: How to add custom code snippets - HivePress Help Center

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.