Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Advertisement
  1. Code
  2. JavaScript
Code

Create a JavaScript Contact Form With the Smart Forms Framework

by
Difficulty:BeginnerLength:MediumLanguages:

In our earlier posts, we listed some free plugins and tools that you can use to create your own forms. One major downside to using free tools to create forms is that the end product might not look as professional and polished as you expect. Similarly, using free libraries to code your own forms might not be possible for people who don't have a lot of coding experience.

In such cases, you can either use third-party services—which can be a bit expensive—or you can purchase a premium framework, form builder, or plugin which offers free support for a certain period of time. In this tutorial, we will take a look at one of the most popular and feature-rich form frameworks available on CodeCanyon to create your own JavaScript forms.

Smart Forms Overview

The tool that we will use today to create our own forms is Smart Forms. This form framework has gained 3,819 sales at the time of writing, and it has an average rating of 4.5 based on 159 reviews. Most buyers who have used the framework in their website like its code quality, features, design, flexibility, and active customer support.

Some of the features of this framework are:

  • responsive framework with over 40 starter templates
  • multi-step forms and modal forms
  • date picker, time picker, month picker, and color picker widgets among others
  • drag-and-drop file uploads
  • AJAX and PHP based, with support for Google reCAPTCHA
  • and the list goes on!

If you want to create a lot of professional-looking forms, using the Smart Forms framework would be a good choice. Do check out all the features and reviews on the framework home page.

Example Forms

To show what you can create with Smart Forms, here are a couple of examples with varying themes and layouts. You can choose to have a social media login button placed either at the top or side by side. There are a lot of color schemes and three different themes available.

Here's a login form.

Login Form Black Theme

And here's that same login form with a different color and the social sign-in buttons on the top:

Login Form Green

Similarly, here are two forms related to placing orders. As you can see, it is possible to create entirely different layouts based on your needs.

Order Form Purple Theme

In the next form, you can see how Smart Forms can create attractive styling like large product option cards.

Order Form Green Theme

The download files contain hundreds of such template files, so you will almost always be able to find a template that suits your needs and styling. Not only that, but the documentation in the download is easy to understand in case you want to create an entirely new layout for your forms.

File Structure and Other Basics

Once you purchase Smart Forms, you will get detailed documentation about the process of creating your own forms and adding them to your own website in the zip download. Here are some key points that you have to remember:

  1. The forms rely on a single main CSS file for most of the styling. Make sure that you load any CSS reset files before loading the CSS for the plugin.
  2. The forms support Font Awesome icons and JavaScript features like AJAX submission and form validation. However, you can disable these features if you don't need them.
  3. The framework loads an additional fallback stylesheet for IE8.

There are three folders inside the extracted archive called dark, flat, and light. These are the three main themes for different forms. Each theme contains three different folders. These are:

AJAX PHP: This folder contains working AJAX PHP forms like a contact form, order form, and more.

JavaScript enhancements: This folder has all the samples for form validation, as well as the date picker and other widgets.

Template samples: This folder includes HTML- and CSS-based form templates to help you build your forms faster. These templates can also act as a basic guideline when you create your own forms.

When creating your own forms, the first step is to load the necessary CSS files using the following lines:

You'll have to wrap your forms in two div elements with the smart-wrap and smart-forms classes.

Creating a Contact Form With Smart Forms

The documentation provides a detailed and easy-to-follow guide on creating different kinds of forms, explaining how to add text input elements, check boxes, radio buttons and file inputs with the theme of your choice applied to them.

In this tutorial, we will create a contact form with a blue theme and fields for name, email, subject, and message. We will need to load one additional CSS file in order to apply the blue theme.

Here is our initial markup for creating the form with a basic skeletal structure:

The wrap-3 class is used to control the width of the form that you are creating. You can set it anywhere from wrap-0 to wrap-4. Unless you change any CSS rules, the wrap-3 class will create the narrowest form, and wrap-4 will cover the full width of the body element. You can create your own CSS rules with additional classes like wrap-5, wrap-6, etc. to adjust the form width.

You have to apply a header-{colorname} class for the theme that you want to apply. The colorname will be the same as the additional CSS file that you loaded. The same goes for the theme-blue class on the body.

You can apply styling to your button elements by adding a class name like pushed, button-pointed, button-left, etc. You can find more information about styling buttons in the Form Buttons section of the documentation.

Smart Forms Button Styling

Now, it's time to add the input elements to our form. All this markup will go inside the div element with the form-body class.

The wrapper div with the class frm-row is helpful when you want to add multiple form elements on the same line. The width of individual form elements is controlled by the colm6 class. The total sum of the classes has to add up to 12 to fill the entire form width. This means that you can either set the width of two form elements to colm8 and colm4 or colm6 and colm6. In the first case, the left element would be twice as wide as the right one. In the latter case, both input elements would have the same width.

With the above markup, the final form will look like the image below:

Example Contact Us Form

Form Validation and Other Enhancements

The framework provides quite a few JavaScript files for adding additional features to the form. For example, there are separate files for input masking and adding file drag-and-drop functionality. The use of each file is explained very clearly in the documentation, so you only have to include those files whose functionality you are actually going to need.

In our case, we just want to validate the form input, so we will load the main jQuery script and two other validation files. One is the core jQuery validate plugin, and the other one provides additional validation methods.

You simply need to add the following script tags to your webpage in order to use JavaScript-based validation.

The last step to enable the validation is to include the following code after the above scripts:

The #contact-form selector above is the value of the id attribute for our form. It will be different for your own forms if you changed that attribute. This line of code simply tells the webpage to validate the information supplied through the form.

Currently, the errors will be displayed without any change in font color or input highlighting. You can use the following code snippet to make the errors stand out better:

Once you add the above code to your webpage, the invalid fields will look like the image below:

Smart Forms - Error Highlighting

Form validation has been covered in great detail in the documentation, so you won't get stuck when implementing it in your own forms.

Final Thoughts

In this tutorial, we created a very attractive contact form using the Smart Forms JavaScript forms framework available from CodeCanyon. One of the best things about using this framework is that all the JavaScript functionality has already been written for you. Also, the forms look very professional with their neat design. You can choose from a large number of options and choose the form layout that suits you best.

The documentation that comes with the framework explains everything really well, so there is very little chance that you will get stuck. In the unlikely event that you do get stuck, the developer offers six months of free support, so all your problems will be resolved quickly! You can check out the demos to see if you like the styling of the forms. Using this framework to create your forms will save you a lot of time and money in the long run, so you should definitely give it a try.

Advertisement
Advertisement
Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.