Javascript required
Skip to content Skip to sidebar Skip to footer

How to Create User Registration Form in Wordpress Without Plugin

How to Create Registration Form in WordPress Without Plugin?

Yes, We can Create a Custom register form without using any plugin.
Below i will tell you step by step Example in details that i have already implemented in a wordpress website.

First We need to Create a template for the register form:
Let say tmpl-register.php is our file name:

How to Create Registration Form in Wordpress Without Plugin_

After a lot of study about WordPress, we found the most asked question about WordPress is: How to Create Registration Form in WordPress Without Plugin?
So the Answer we have explained below. Head over the code and show your talent.

Yes, We can Create a Custom register form without using any plugin.
Below I will tell you to step by step Example in details that I have already implemented in a WordPress website.

First We need to Create a template for the register form:
Let say tmpl-register.php is our file name:

Sign Up Form

Now the form is ready. Please check for the id and proper classes.
In this form i am using the Jquery validation.

To use jquery you need to include the file jquery.validate.js. You can get this online by Search on google.
you can add the jquery in your footer.php file or any new js file.
I am using the validation in the footer.php file
First we need to include the file

And the code for Validation:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

<script>

jQuery ( document ) . ready ( function ( )

{

$ ( "#adduser" ) . validate ( {

submitHandler : function ( )

{

$ . ajax ( {

type : "POST" ,

url : '<?php echo get_template_directory_uri(); ?>/template-parts/reg-ajax.php' ,

data : $ ( "#adduser" ) . serialize ( ) ,

success : function ( response ) {

if ( response == 1 )

{

$ ( '.plswait' ) . hide ( ) ;

$ ( '.success' ) . show ( ) . delay ( 8000 ) . fadeOut ( ) ; ;

$ ( '.validation' ) . delay ( 8000 ) . fadeOut ( ) ;

//window.location.href = "<?php echo site_url(); ?>";

//$('#signin-model').modal('show');

$ ( '#adduser' ) [ 0 ] . reset ( ) ;

} else {

$ ( '.errormsg' ) . show ( ) ;

$ ( '.errormsg' ) . html ( "<span>" + response + "</span>" ) ;

$ ( '.plswait' ) . hide ( ) ;

}

}

} ) ;

} ,

rules : {

fullname : {

required : true ,

} ,

lastname : {

required : true ,

} ,

pass : {

minlength : 5

} ,

cpass : {

required : true ,

equalTo : "#pass"

} ,

email : {

required : true ,

email : true

} ,

phone : {

required : true ,

number : true ,

maxlength : 16 ,

minlength : 10 ,

} ,

} ,

messages : {

username : {

required : "Please enter fullname" ,

} ,

pass : {

required : "Please provide a password" ,

minlength : "Your password must be at least 5 characters long"

} ,

email : {

required : "Please enter a valid email address" ,

} ,

phone : {

required : "Please provide phone number" ,

} ,

}

} ) ;

} ) ;

</script>

In the Above code you will see the id and the classes used for the proper validation. And you can change and add the new messages as per your requirements.

Here you noticed i have given the url.
url: ' /template-parts/reg-ajax.php',

So the New file would be reg-ajax.php. This file is used for Insert the new user to the database.

Just follow the code you will understand.

File name: reg-ajax.php. As you see i have given in the url template-parts/reg-ajax.php. That means i have put this file in the template-parts folder into my theme folder. you can place it outside the folder as you want with changing of your path name.

reg-ajax.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

< ! -- ? php

include ( '../../../../wp-config.php' ) ;

global $ wpdb ;

$ user = $ _POST [ 'fullname' ] ;

$ email = $ _POST [ 'email' ] ;

$ fname = $ _POST [ 'fullname' ] ;

$ lname = $ _POST [ 'lastname' ] ;

$ phone = $ _POST [ 'phone' ] ;

$ pass = $ _POST [ 'pass' ] ;

$ date = date ( 'Y-m-d H:i:s' ) ;

$ table = $ wpdb -- -> prefix . "users" ;

$ sel = "Select * from $table  where user_login= '" . $ email . "'" ;

$ posts = $ wpdb - & gt ; get_results ( $ sel ) ;

$ rowCount = $ wpdb - & gt ; num_rows ;

if ( $ rowCount & gt ; 1 )

{

echo 'user already exsits' ;

} else {

$ default_newuser = array (

'user_pass' =& gt ; $ pass ,

'user_login' =& gt ; $ email ,

'user_email' =& gt ; $ email ,

'first_name' =& gt ; $ fname ,

'last_name' =& gt ; $ lname ,

'role' =& gt ; 'seller'

) ;

$ users = wp_insert_user ( $ default _newuser ) ;

if ( ! is_wp_error ( $ users ) ) {

echo 'Registration complete.  Go to <a href="' . get_site_url ( ) . '/login">login page</a>.' ;

}

else {

echo "User Already Exists. Please try with another Email Address." ;

}

}

? & gt ;

I have placed all three files in the template-parts folder. In this Twenty-sixteen theme used.

You can use in any theme. the code will work just use the proper id and remember to include the jquery as well.

You can add more fields and validation according to the requirements.

If you'd like to see how to create landing pages and sales funnels with WordPress?

You can click here to learn more.

If you have more question go Comments below. We would love to hear from you,

Enjoy.

wordpress wp

Last modified: 12/05/2019

About the Author: Admin

How to Create User Registration Form in Wordpress Without Plugin

Source: https://developergang.com/create-custom-register-form-wordpress/