PressTigers

How To Create A New User Form From Front End

WordPress provides a custom user form which can be used to register a new user. It only requires a user name and email. After successful signup, password will be emailed back to you. Next time when you login to the website with the password that was sent you back in email and you complete your profile, after that you need to change your password again to something that will be easy for you to remember.

But what if you want to make your own custom registration form? Instead of user to go through the above mentioned stress, why not register by a form where you can place consistent information like user name, password, first name, last name, biography etc.

These are the default custom fields in WordPress User Profile. You can add your custom fields to it as well. For this, firstly you need to create a user form using the following code:

After the submission of form, you can check the required fields and ask your user to fill those fields:

Further, you can validate the email and other field values here as well. You can also check the username and email id if it exists or not.

To check if username already exists or not, use the following code:

For validating username, use the following code:

To check if email ID is valid or not, use the following code:

To check if email address already exists or not, use the following code:

For validating Password, use the following code:

If any required field is missed or any field validation is false then print this ‘$error’. Its value should be greater than 0, error messages will be displayed. If $error’s value is equal to 1 then all the fields are good to go. Now we have to create a new user:

wp_inser_user() will return the id of current user inserted on success, else it will return the wp_error object.

On success, if you want to login a current registered user, then you can do this by using the following code:

You can make this form by using a shortcode or by any custom template. Now you can style it with respect to the design of your theme.

User Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

    Get in Touch