Registration form in wordpress and store data in DB using shortcode

In this tutorial, we will learn that how to make a simple registration form which will accept the data from the user and that data will be stored in the database. We will use phpMyadmin as backend DB. To do so, just follow these steps:

Step 1:

Open function.php as we will make the shortcode which we will use in our new page later on. If you don’t know about the shortcodes in wordpress, let me give you a brief introduction about what is shortcode. “A shortcode is a small code which is being defined generally in the function.php file and then the UI can be added to any of the page. ” I hope now you have a rough idea about shortcode. Now follow the next step:

Step 2:

Now you will need to add the code for making the form. For that add the following code in your opened file.

The above code will make a form with some fields specified in the above form. You can edit your entries according to the requirement of your form. Now your form is ready. Step ahead further..


As your form is ready now you need to apply some validation on the form so that user will not submit the form without the desired data. I think I don’t need to tell you about what is validation and why we use that. So now we need to make the following two functions for validation.

first function is:

Second function is:

Step 4:

With above two functions, your form is ready with all the validations for required fields, email etc. Now you need to make another function for completing the form and insert the data into database as user entry. To do so, copy and paste the following code:

Step 5:

Your form is ready. Now add the last line to your function.php file which we will use latter in our page.

Step 6:

All set. Now just make a new page and then copy and paste the following short-code there:

Now save your page and test it yourself.

If you have any query regarding the code or any concept, feel free to contact me or comment the post.