Skip to main content

HTML5 and jQuery Powered Signup Form

In this tutorial we are going to create a singup/registration form with html5 form attributer and jQuery form validate plugin. jQuery Validation is a powerful jQuery form validation checking plugin. We can check forms validity very easily with this plugin.

Live Demo Download Source

MySQL

First we have to create users table that will hold all user information like name, username, password, and email.

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) NOT NULL,
  `username` varchar(64) NOT NULL,
  `password` varchar(64) NOT NULL,
  `email` varchar(124) NOT NULL,
  PRIMARY KEY (`id`)
);

HTML

This following html code resides in index.php file. That file holds the basic of registration form.

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Sign Up</title>

  <!-- bootstrap style sheet -->
  <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">

  <!-- general styling -->
  <link rel="stylesheet" type="text/css" href="assets/css/style.css">

</head>
<body>
  <div class="container">
    <div class="main">

      <div class="alert alert-error">
        <!-- error message will be shown here -->
      </div>

      <form class="form-horizontal" action="" method="post">

        <div class="control-group">
          <label for="name" class="control-label">
            <span>Full Name</span> <span class="required">*</span>
          </label>
          <div class="controls">
            <input type="text" name="name" id="name" required placeholder="Full name">
          </div>
        </div>

        <div class="control-group">
          <label for="username" class="control-label">
            <span>Username</span> <span class="required">*</span>
          </label>
          <div class="controls">
            <input type="text" name="username" id="username" required placeholder="username">
          </div>
        </div>

        <div class="control-group">
          <label for="password" class="control-label">
            <span>Password</span> <span class="required">*</span>
          </label>
          <div class="controls">
            <input type="password" name="password" id="password" required placeholder="Password">
          </div>
        </div>

        <div class="control-group">
          <label for="password2" class="control-label">
            <span>Repeat password</span> <span class="required">*</span>
          </label>
          <div class="controls">
            <input type="password" name="password2" id="password2" required placeholder="Repeat Password">
          </div>
        </div>

        <div class="control-group">
          <label for="email" class="control-label">
            <span>Email</span> <span class="required">*</span>
          </label>
          <div class="controls">  
            <input type="email" name="email" id="email" required placeholder="Email Address">
          </div>
        </div>

        <div class="controls">
          <input class="btn btn-primary" id="submit" type="submit" value="Sign Up!">
        </div>

      </form>

      <hr>

    </div>
  </div>

  <!-- jquery library include -->
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

  <!-- jquery validation plugin include -->
  <script src="assets/js/validation.min.js"></script>

  <script src="assets/js/script.js"></script>

</body>
</head>

Take a look on the above html markup, we used required attribute on input fields. It is a html5 attribute. It tells the browser that this field it required and user must have to fill this field.

jQuery

The following JavaScript resides in script.js file. This file holds jQuery Validation plugin's configurations. Here we needs to set some rules. Take a look on the comments to know more about the rules. We will also need to create a function called ajaxSubmit. This function will submit the form asynchronously through ajax request.

$(function(){

  var form  = $('form');
  var submit   = $('#submit');
  var alert  = $('.alert');

  // validate form
  form.validate({
    // validation rules
    rules: {
      // name field (required , minimum length 3)
      name: {
        required: true,
        minlength: 3
      },
      // username field (required , minimum length 3, max 8)
      username: {
        required: true,
        minlength: 3,
        maxlength: 8,
      },
      // password field (required , minimum length 6, max 16)
      password: {
        required: true,
        minlength: 6,
        maxlength: 16
      },
      // password2 field must be equal to password field
      password2: {
        equalTo: '#password'
      },
      // email field only required
      email: 'required'
    },
    // submit ajax request
    submitHandler: ajaxSubmit
  });

  /**
  * ajax submit function
  * sending simple ajax request
  **/

  function ajaxSubmit() {
    $.ajax({
      url: 'ajax.php',
      type: 'POST',
      dataType: 'json',
      // form serialize data
      data: form.serialize(),
      beforeSend: function(){
        alert.fadeOut();
        submit.val('Sending...').attr('disabled', 'disabled');
      },
      success: function(data){
        if ( data.status === 'success' ) {
          // if responce status == success redirect to success page
          $(location).attr('href','success.html');
        } else {
          // not success! show error messages
          alert.html(data.status).fadeIn();
          submit.val('Sign Up').removeAttr('disabled');
        }
      },
      error: function(){
        // show error message
        alert.html('Sending request fail').fadeIn();
        submit.val('Sign Up').removeAttr('disabled');
      }
    });
  };
});

PHP

We are now ready to write some php code. The following code is resides on ajax.php file. This file receives ajax request and checks some validity.

<?php
include 'config.php';
include 'function.php';
# mysql db connect
dbConnect();

header('Content-type: application/json');

if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
  if ($_POST['name'] !== '' and $_POST['username'] !== '' and $_POST['password'] !== '' and $_POST['email'] !== '' )
  {
    if ($_POST['password'] === $_POST['password2']) {
      # prevent sql injection
      $name     = mysql_real_escape_string($_POST['name']);
      $username   = mysql_real_escape_string($_POST['username']);
      $password   = mysql_real_escape_string($_POST['password']);
      $email     = mysql_real_escape_string($_POST['email']);

      # username exist or not
      if (!user_exist($username))
      {  # insert new user
        if (inser_new_user($name, $username, md5($password), $email))
        {  # throw success status
          json_status('success');
          # throw errors
        } else { json_status('Request not complete'); }
      } else { json_status('Username already exist'); }
    } else { json_status('Passwords are not matched'); }
  } else { json_status('You must complete all the fields'); }
}
?>
Note: It is not a secure way to process registrations data form server side. If you want to implement it in your real life project you need to do more validation.

Comments

  1. Why does it show "Sending request fail"

    ReplyDelete

  2. Many mistake HTML as a programming language but rather its a markup language and not progaramming language. HtML5 is the latest and technically most advanced version of HTML. To know more
    html5 training in chennai|html5 training chennai

    ReplyDelete
  3. very useful post. I can easily remove this from my blog. Thanks a lot. For more details visit. JAPAN TSUNAMI 2011 comment link (207) welcome to new tab.

    ReplyDelete
  4. The best thing about HTML5 is that it allows the developers to embed the video files, audio files, and high quality graphics without any third party applications.
    html5 training in chennai | html5 training institutes in chennai | Fita Chennai reviews

    ReplyDelete
  5. Hi, actually I'am new to angularJs and infact I'am learning angularjs with online training. I'am having doubt, if you could solve the doubt for me that would be very helpful. The doubt is, how can I reset a “$timeout”, and disable a “$watch()”?
    Regards,
    angularjs training in Chennai | angularjs training | angularjs training Chennai

    ReplyDelete
  6. You can go through your entire life and not ever hear the term HTML or realize the role it plays every time they go to a websites. When you are learning to make websites, a HTML codes list will become one of your best tools, and the first step to losing your fear. Take a look: html code

    ReplyDelete
  7. Fantastic post and excellent applications for your business with affordable rates website design service

    ReplyDelete
  8. PHP is the best language to develop data driven websites. PHP is used by majority of the ecommerce websites. Learning PHP can give you a great future for sure.
    PHP training in Chennai | PHP course in Chennai | PHP training institute in Chennai

    ReplyDelete
  9. Dot net is a Microsoft product so it is the best language to develop applications for windows and it is supported well on the windows platform. Dot net is prefferd globally and a renowned platform with lots of job opportunities.
    Dot net training in Chennai | .NET training in Chennai | Dot net course in Chennai

    ReplyDelete
  10. I have completely read your post and the content is crisp and clear.Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated.
    Android training in Chennai | Android course in Chennai | Android training institute in Chennai

    ReplyDelete
  11. The blog you presented was very nice and interesting which helped me to get update on the recent technologies.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  12. The blog you presented was very nice and interesting which helped me to get update on the recent technologies.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  13. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Web Designing Course in Chennai | web designing training in chennai

    ReplyDelete
  14. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  15. Wow, Explained well and useful example guys. Your post really helped me to create the form by myself. Pls check it out here,
    Best AngularJS Training in Chennai | AngularJS Training and Placement assistance | AngularJS Training Institute in Chennai

    ReplyDelete
  16. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
    hotmail sign in | red ball 1

    ReplyDelete
  17. Great Combinations of Html, mysql and Jquery. Really It will be more helpful for the beginners. I will share your post.
    Check out some of the best AngularJS concepts which can help you as well.AngularJS Training in Chennai |Best AngularJS training institute in Chennai

    ReplyDelete
  18. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    tanki online | 2048 game| tanki online game

    ReplyDelete
  19. Very interesting and much more informative, thanks for sharing your information and valuable time.
    PHP course in chennai
    PHP Training in velachery
    PHP Training

    ReplyDelete

  20. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information

    White Label Website Builder

    ReplyDelete
  21. Petty article...Thanks for sharing your useful and interesting blog with unique content..keep updating.
    Best Linux Training Institute in Chennai | No.1 Linux Training Center in Chennai | Red Hat Linux Training Center in Chennai

    ReplyDelete
  22. Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind. Very interesting and useful blog!
    PHP Training in Chennai
    PHP Course in Chennai

    ReplyDelete
  23. I found a lot of interesting information here. A really good post. Thanks for sharing.
    Final Year Project Center in Chennai | Final Year Project Center in Velachery

    ReplyDelete
  24. Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
    Regards,
    Tableau training in Chennai | Tableau Courses Training in Chennai | Tableau training Institute in Chennai

    ReplyDelete
  25. This is really too useful and have more ideas from yours. keep sharing many things and thanks for sharing the information.

    Best python training institute in Kanchipuram

    ReplyDelete
  26. Nice and informative article. Thanks for sharing such nice article, keep on updating.

    CandC++ programming training academy in Kanchipuram

    ReplyDelete
  27. Nice post... Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating...

    Best Java Training Academy in Kanchipuram

    ReplyDelete
  28. I have read your blog. It’s very informative and useful blog. You have done really great job. Keep update your blog.

    Best Tally Courses Training Academy in Kanchipuram

    ReplyDelete
  29. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...

    Best Graphics Designing Training Academy in Kanchipuram

    ReplyDelete
  30. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete
  31. Thank you so much for sharing. Keep updating your blog. It will very useful to the many users.
    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete
  32. I have read your blog its very attractive and impressive. I like it your blog.
    Best Software Testing Training Academy in Kanchipuram

    ReplyDelete
  33. Your Blog is nice and informative..Thanks for sharing this valuable information with us..I am visiting this website regularly, this web site sharing nice thoughts

    Best MATLAB Training Academy in Kanchipuram

    ReplyDelete
  34. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...
    Best ccnp Training Academy in Kanchipuram

    ReplyDelete
  35. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  36. Thanks for this grateful information. all this information is very important to all the users and can be used good at all this process.


    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete
  37. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. so keep on sharing such kind of useful blogs.

    Best TALLY ERP 9.0 Training Academy In Kanchipuram

    ReplyDelete
  38. wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing
    Best C++ Training Institute in Kanchipuram

    ReplyDelete
  39. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Best web Designing Training Training Institute in Kanchipuram

    ReplyDelete
  40. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.
    Best Tally erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  41. Nice..You have clearly explained about it ...Its very useful for me to know about new things..Keep on blogging..
    Best JAVA and J2EE Course Training Institute in kanchipuram|

    ReplyDelete
  42. Hi, am a big follower of your blog. I am really happy to found such a helpful and fascinating post that is written in well manner. Thanks for sharing such an informative post. keep update your blog.
    Best CCNA Course Training Institute in kanchipuram|

    ReplyDelete
  43. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.
    Best Best Web Designing and Development Course Training Institute in kanchipuram|

    ReplyDelete
  44. great doing. and i happy to visit your blog to know about this wonderful information. thanks for sharing. keep updating.
    Best Best Web Designing and Development Course Training Institute in kanchipuram|

    ReplyDelete
  45. Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog..
    Best Python Course Training Institute in kanchipuram|

    ReplyDelete
  46. Very impressive and informative blog.. thanks for sharing your valuable information.. it is very useful and easy to learn as well... keep rocking and updating... looking further..
    Best Tally Erp9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  47. Quite Interesting post!!! Thanks for posting such a useful post. I wish to read your upcoming post to enhance my skill set, keep blogging.
    Best Web Technologies Course Training Institute in kanchipuram|

    ReplyDelete
  48. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me…
    Best Linux Certification Course Training Institute in kanchipuram|

    ReplyDelete
  49. Quite Interesting post!!! Thanks for posting such a useful post. I wish to read your upcoming post to enhance my skill set, keep blogging.
    Best Web Technologies Course Training Institute in kanchipuram|

    ReplyDelete
  50. Attend The Data Science Course From ExcelR. Practical Data Science Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Science Course.
    Data Science Course

    ReplyDelete
  51. Nice Post! It is really interesting to read from the beginning & I would like to share your blog to my circles, keep your blog as updated.
    Best Tally ERP 9 Course Training Institute in kanchipuram|

    ReplyDelete
  52. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    Best Graphic Designing Course Training Institute in kanchipuram|

    ReplyDelete
  53. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me
    Best PCB Training Course Training Institute in kanchipuram|

    ReplyDelete
  54. your blog contain very useful information. Really hereafter I am very big follower of your blog..
    Best MATLAB Course Training Institute in kanchipuram|

    ReplyDelete
  55. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me…no:1
    HP QTP / UFT Automation training institute in kanchipuram.

    ReplyDelete
  56. Great post....Thank you for posting the great content……I found it quiet interesting, hopefully you will keep posting such blogs…Keep updating your creative and awesome blog.
    Best Tally Erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  57. The best thing is that your blog really informative thanks for your great information! I have got some important suggestions from it.
    Best Printed Circuit Board (PCB) Course Training Institute in kanchipuram|

    ReplyDelete
  58. The information you have deliver here is really useful to make my knowledge good. Thanks for your heavenly post.
    Best Best Web Designing and Development Course Training Institute in kanchipuram|

    ReplyDelete
  59. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    Best Tally erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  60. Your post explain everything in detail and it was very interesting to read. Thank you sharing.
    Best Tally Erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  61. I am read your post was very interesting good valid information
    keep sharing more information...
    Best Tally Erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  62. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information, this is useful to me…
    Best Tally Erp9 Course Training Institute in kanchipuram|

    ReplyDelete
  63. Really it was an awesome information...very interesting to read..You have provided an nice blog....Thanks for sharing..
    Best JAVA / J2EE / J2ME Course Training Institute in kanchipuram|

    ReplyDelete
  64. Excellent post. I have read your blog it's very interesting and informative. Keep sharing.
    Best JAVA / J2EE / J2ME Course Training Institute in kanchipuram|

    ReplyDelete
  65. Nice post.. Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating...
    Best C & C++ Course Training Institute in kanchipuram|

    ReplyDelete
  66. Very nice post here and thanks for it .I always like and such a super blog of these post.Excellent and very cool idea and great blog of different kinds of the valuable information's.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  67. This is really impressive post, I am inspired with your post, do post more blogs like this, I am waiting for your blogs.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  68. Interesting post!!! Thanks for posting such a useful information. I wish to read your upcoming post to enhance my skill set and keep blogging.
    Best Tally Erp 9.0 Course Training Institute in kanchipuram|

    ReplyDelete
  69. This is excellent information. It is amazing and wonderful to visit your

    site.Thanks for sharing this information, this is useful to me.
    Best Selenium

    Automation Course Training Institute in kanchipuram
    |

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiple File Upload with Progress Bar using PHP & jQuery

Some days age I have created a post that deals with How we can upload file with progress bar using php and jQuery. Some of my readers asked me how we can upload multiple files with progress bar. In this post I am going to show you how we can upload multiple files with progress bar.We can upload multiple files with progress bar exactly same way as I shown previous. But we need to do some modification with our file upload form and our php script to handle multiple files.

Force File Download with PHP

If you want to control or track your downloadable contents then a force file downloader script can give you more option. Especially if you want make images or other stemming contents like music file (mp3, wav, ogg), video files (flv, mp4, ogg, 3gpp), css, JavaScripts or even a php file downloadable then you must need to use a force file downloader script.
In this post I am going to share a simple but useful force file downloader script.

File Upload with Progress Bar using jQuery and PHP

In this post you will learn how to create a AJAX file uploading system with progress bar using jQuery and PHP. For this purpose we will going to use jQuery Form Plugin. It is a easy to use and powerful jQuery AJAX form submitting plugin. It supports XMLHttpRequest Level 2 and iframe file transportation. That's why it will work for both old and new browsers.