How to Change a User Role via Form
The crucial thing to do once the user has registered on the website is to allow them to update their profile. More specifically, it is a way to change a WordPress user role as it gives different access levels to the website. In this tutorial, you will learn how to change the user role thanks to JetFormBuilder forms.
JetFormBuilder forms will help you change the current user role to another one after the form submission. The vital point in this process is Post Submit Actions. Let’s find out what options will be suitable for changing WordPress user roles via a form.
Related Post Submit Actions
The first action that may be helpful is Update User. Apply it to let the user edit their profile. After you select this post submit action, you can set the user role created via the form.
Another relevant post submit action is Register User, which can be used initially to add a new user. However, it is not the only feature of this post submit action. You can also use it to set the role of the newly-added user.
Update User Form
The starting point is creating a form. Go to JetFormBuilder > Add New. The form is not empty by default. There are Hidden, Text, and Submit Fields by default. Delete them or edit if needed.
Name a form and place all the needed fields to create a WordPress form that will suit you.
Note that the User ID hidden field is obligatory as you need it for the correct work of the form. To find out the User ID, go to the WordPress Dashboard > Users and hover the mouse over the required user name. A small pop-up window with a user ID will appear.
Head back to the form editor. After customizing the blocks, move on to JetForm Settings > Post Submit Actions. Choose the “Update User” option from the drop-down list and proceed to its editing.
Set the Fields Map values and proceed to the User Role drop-down. Pick the role from those available to you. After selecting the option, adjust the Messages Settings if needed and update the action.
Head to the Pages > Add New and click on the plus-shaped button to add a new block. Find the JetForm block and place it on the page. Configure the JetForm Form Settings.
Adjust other JetForm Settings if desired and click on the “Publish” button. The next step is to place a form on the page.
- Choose Form — select a form you want to be displayed on the page;
- Fields Layout — choose between “Column” and “Row” options;
- Required Mark — change the default asterisk symbol that will be shown next to the required field;
- Submit Type — define whether the page will be reloaded after the form submission or not;
- Enable form pages progress — toggle to add a step indicator above the form. To configure the steps, use the Form Break Field.
Check Advanced Settings if you want to set the CSS classes or work with the JetStyleManager plugin to customize the form straight in the page editor.
Publish the page once you have finished editing and view it on the front end.
Once you click on the “Submit” button, check the results by navigating to the WordPress Dashboard > Users tab.
The WordPress user role has been updated from subscriber to editor.
Register User Form
To add a new user while registration, we need to repeat some initial steps made while creating the Update User Form. Head to JetFormBuilder > Add New.
The form already contains Hidden, Text, and Submit Fields by default. You can delete the fields you don’t need.
Give a title to the form and pick the needed fields by clicking on the plus-shaped button. Edit them and move on to the JetForm Settings. In the Post Submit Actions tab, choose “Register User.” Open the action editor by pushing the button under the drop-down menu.
Firstly, you can toggle Allow creating new users by existing users and define who can add a new user. Select the corresponding field options in the Fields Map section and choose the role for a new user. Type in the other fields if needed. However, they are not necessary in this specific case.
Update the action and publish the form if everything is set accordingly. To apply the form to the page, go to Pages > Add New.
Place the JetForm block on the page and proceed to the JetForm Form Settings.
- Choose Form — pick the newly-created form;
- Fields Layout — define in which way the field label and its bar will be placed, as “Column” or “Row”;
- Required Mark — set the symbol displayed next to the required fields;
- Submit Type — choose between “Page Reload” and “AJAX” options;
- Enable form pages progress — toggle if you work with Form Break Field and want to apply a step indicator above the form.
Next are Advanced Settings that contain one field where you can put Additional CSS class(es) if needed. You can also use the JetStyleManager plugin to customize the form appearance while editing.
Once you have adjusted the settings, publish the page and check it out.
Click on the “Sign Up” button and go to the WordPress Dashboard to check if the user was created. Open Users > All Users.
The new user has been created and displayed.
Now you know how to update WordPress user roles via JetFormBuilder forms using the “Update User” and “Register User” post submit actions.