All posts by XhtmlJunction

About XhtmlJunction

If you have a flair for writing and you have an interest in web development industry, then you have the best opportunity for connecting with web development giants. Write for XthmlJunction and instantly broadcast yourself to the web development industry.

Mobile Compatible Wordpress Site

An Ultimate Guide for Making Your WordPress Site Mobile Compatible

Do you know over 70% of the total traffic comes strictly from mobile devices? It is an undeniable truth that Google favours mobile-friendly or responsive websites. As per a report produced by Google, 90% of users move between different types of devices – like tablets, smart phones, desktop, or TV – to browse or purchase something via internet. With the rapid adoption of multi-screen devices, believe it or not, it became a must to either create a mobile-friendly website or make it fully responsive.

Keeping today’s mobile dominated era in mind, many businesses have already made their blogs/sites mobile-friendly or responsive, but there are many website owners who still have not adopted this trend. If you’re also one of them, in this article, we’ll walk you through various ways you can create a mobile compatible version of your WordPress site to deliver you visitors a superior mobile experience.

Before proceeding to different ways of making your WordPress site mobile-friendly, we recommend you to test how well your website looks on various devices.

Test Your Mobile Interface

Here’re some great tools using which you can test the usability of your site from the different devices, including iPhone or other smart phones.

Let’s have a look at them!

  • iPadPeek: It’s a simulator that allows you to check how your website will be rendered on the iPad.
  • iPhone 4 Simulator: Using this simple simulator, you can test how your website will look like on the iPhone.
  • Opera Mobile Simulator: Using this simulator, you can view your site as on Java based mobile phones and devices.
  • W3C mobileOK Checker: This checker will perform several tests on your website to determine how much friendly it is to mobile devices. Your website will be called mobileOK, if it passes all the tests successfully.
  • MobiReady: This handy tool will let you test your website’s W3C mobileOK and dotMobi compliance, and provide you report about how well your website will perform on mobile devices.
  • Am I Responsive: One of the best tools to check whether your website is responsive or not.
  • Responsive Design Checker: Another great tool to check the responsiveness of your website.

Different Ways to Make Your WordPress Site Mobile Friendly

Once you’ve tested your WordPress site on different devices, it’s time to make it friendly for all viewers and enrich its usability. To aid you in this process, here we’ve explained several efficient approaches. You can opt for any one of them, depending on your existing site or which type of compatibility you want.

Let’s get started!

Use/Upgrade to a Responsive Theme:

Using a Responsive theme is one of the best approaches to make your WordPress site mobile compatible. No matter which device or screen size your visitors are using, a Responsive Theme changes the layout to fit the dimension of web browser. While using a responsive theme, one of the best things is that you don’t have to worry about mobile optimization or using any plug-in for your website.

One of the most efficient ways of converting your current WordPress theme into a responsive one is by using a responsive CSS file. If you’re looking for a D.I.Y solution, prerequisites would be you should have intermediate knowledge of HTML/CSS and WordPress. Otherwise, you can hire an expert web developer/outsource. Personally, we recommend you to purchase a high quality responsive theme from a reputed WordPress theme provider such as WooThemes and elegant themes.

For your convenience, here we’ve listed several responsive WordPress themes that you can use:

Through Domain Mapping:

If you don’t want to use a responsive theme, you can use a separate mobile theme via Domain Mapping. Using this approach, you also don’t require to use a responsive CSS file for making your site mobile compatible. To deliver your mobile visitors a great browsing experience, all you need to create a sub domain – like mobile.yoursite.com or m.yoursite.com – for the mobile version of your site, and set a mobile theme for your configured sub domain.

That’s way, whenever visitors will enter the original URL of your site on a mobile device, they’ll be redirected to the custom mobile URL through domain mapping. Also, they can visit your blog by directly entering your site’s mobile URL i.e. m.yoursite.com. If you’re using WordPress and unable to add domain mapping functionality manually, we suggest you to use WordPress MU Domain Mapping plug-in to handle entire domain mapping process.

Customised Mobile Site Solutions:

If you face any problem while using any of above two methods, then you’re suggested to go for customised solutions to get the mobile version of your site. Here we’re listing three of the best services using which you can create professional mobiles sites without any programming skills.

Let’s have a look at them!

# Mobify :

Mobify is a popular service that lets you build mobile version of your website in a very short span of time, using a simple and powerful toolkit. It is used by some of the world’s most successful brands such as Starbucks, Ideeli, Expedia, Crocs, and Coastal. It is a great service for designers and perfect solution for SMBs and enterprise level eCommerce. Mobify prices start at $495 per month.

# MoFuse :

MoFuse is another service that allows you to build mobile websites at affordable price. One of the best things about this service is that you can use custom CSS to get the desired look and feel of your site on mobile. Whether you’re a business owner or reseller, MoFuse could be a perfect choice for you. You won’t believe that popular blogs like Makeuseof, Readwriteweb, and Mashable are using this service. MoFuse prices start as low as $9/month.

# Onbile :

Onbile is an online platform that allows you to create a low cost, high-quality and fantastic mobile version of your site without any programming. It provides you an easy-to-use control panel through which you can choose from a wide range of premium templates to fit your requirements. It is absolutely free for personal and non-commercial websites.

Using a Mobile Plugin :

Most of the issues in WordPress can be fixed by using an appropriate plug-in, and making your site mobile compatible is not exceptional. Here’re several plug-ins that will automatically optimize your WordPress site for all types of mobile devices.

Let’s go through them one by one!

# WPTouch Pro :

WPTouch Pro is a fast, efficient, and flexible WordPress plug-in that is designed to deliver great mobile experience to users. It is built using RESS (Responsive Design + Server Side Optimization), and loads web pages up to 3X-5X faster than responsive or desktop websites. You can pick from 4 beautiful and professionally designed mobile themes and customize them as the way you want.

This elegantly designed plug-in features an easy-to-use Admin panel with powerful setup options. Built-in sharing options allow users to easily share your content on social media sites. In addition, iOS users can add the mobile version of your site as a web app on their devices. It’s available in 21 languages and used by thousands of reputed sites like CNN, Freakonomics, Grolsch, and Stephen Fry.

# WPTap :

WPTap offers a range of WordPress Plug-in/Themes that can instantly turn your WordPress site into a stunning mobile version for Android, iPod Touch, iPhone, and touch-based Blackberry devices. All the WPTap themes come with all the essential features of a WordPress blog such as login, search, archives, photos, tags, categories, and more.

Also, WPTap comes with a user-friendly WordPress admin panel through which you can customize your theme. Whenever a user accesses your site through a mobile device, it automatically detects the type of mobile device and activates the tap theme you’ve chosen without interfering with your regular PC theme.

# WP Mobile Detector :

WP Mobile Detector is a WordPress plug-in that automatically detects whether a person is using a standard mobile device or an advanced mobile device, and loads a compatible mobile theme for each. With notable features like detection of more than 5,000 mobile devices, image resizing, advanced mobile statistics, and automatically formatted content, the WP Mobile Detector delivers your visitors a seamless mobile experience.

The WP Mobile Detector plug-in doesn’t require any configuration. All you’ve to do is to install and activate it. You can either choose from seven pre-installed mobile themes or build your own custom mobile theme. Other features include cross-platform compatibility, collapsible menus, dynamic page loading, touch-optimized layouts, and more.

# JetPack :

JetPack is considered as must-have plug-in for every single WordPress site. It comes with a with a number of delightful features – like Related Posts, Contact Form, Google+ Profile, Infinite Scroll, Tiled Galleries etc. – but may be not all of them are useful for you. Yet, there are numerous features that can really supercharge your site.

One such feature of JetPack is the ability to convert your WordPress site into a mobile compatible version. The Mobile Theme module of this plug-in allows you to do so. To use the Mobile Theme, you’re just required to activate this module via Jetpack dashboard, and then Jetpack will automatically optimize your site for all types of mobile devices.

#Obox Mobile:

Obox Mobile, developed by Obox Design, is a WordPress plug-in through which you’ll be able to convert your WordPress site to a simple-to-navigate layout fully compatible with all type of mobile devices, including Android, Windows, Blackberry, or iPhone. Even, all layouts works seamlessly with retina display mobile devices.

This handy plug-in has an innovative Visual customizer, featuring a live canvas that enables you to customize your mobile site to fit your requirements by allowing you to change logos, fonts, colors, and backgrounds. Furthermore, it allows you to insert your Google Analytics tracking code into mobile version, so you could track your visitors on mobile devices.

# Mobile :

Mobile, created by ithemes, is another plug-in that enables you to create device-aware mobile themes for your WordPress site. It comes with a built-in style manager using which you can easily customize basic styles for your mobile theme’s headlines, fonts, navigation, and footer.

Apart from this, you can choose from 4 mobile-ready, customizable themes or create your own. It also has support for WordPress v3.0 custom navigation menus, and allows you to assign separate themes to specific platforms to deliver your users a better experience. You can assign an existing navigation menu or a separate mobile-specific menu for your mobile version.

# WP Mobile Edition :

WP Mobile Edition is a simple and easy to use WordPress plug-in for mobilizing your WordPress site for smart phones, including Android, iPhone, Blackberry, and Windows Phone. It has a mobile switcher that automatically detects whether a visitor is on mobile or not, and switches between default desktop theme and loads a mobile theme.

Besides, it creates a mobile XML Sitemap of your WordPress site in order to maximize the visibility of its mobile version in search engines. There are 16 different color schemes to choose from. You also don’t require having knowledge about SEO, as this great plug-in automatically optimizes your site for search engines.

# MobilePress :

MobilePress is another simple WordPress plug-in that renders a mobile compatible version of your blog or website. It enables you to choose from some custom themes for different mobile devices. In addition, a few mobile friendly settings are available for custom appearance.

Google PPC Tips

10 Best Practices to Optimize Your Google PPC Ads [Infographic]

Google AdWords is a cost-effective way to boost your website traffic, target your customers, improve lead generation, generate more revenue, and get the edge with search engines. For a PPC professional, Google Adwords campaign optimization is a challenging job, as online advertising is constantly changing and Google regularly improves AdWords system with new updates and features.

Many of the advertisers and marketers spend most of their time into organizing AdWords campaign properly, selecting keywords carefully, and managing their daily budget prudently, but they often forget to devote a little amount of time for optimizing their AdWords campaigns. The reason is that they don’t know how a small change to a campaign ad can have a dramatic impact on its performance. As the competition in the PPC arena is growing rapidly, you’re also required to optimize your AdWords campaign to get the most out of it.

Learning PPC best practices will not only help you maximize your ROI with Google AdWords, but also raise your campaigns to new heights. To help you get the best possible results from your PPC ads, we’ve designed an infographic showing you 10 most basic and proven AdWords best practices that you should implement while setting up your campaigns. Hope, our infographic will help PPC professionals of all levels enhance the effectiveness of their AdWords PPC campaigns and get the desired results.

Let’s have a look at the infographic!

Google Adwords Optimization

HTML5 Canvas Tutorial

How to create 2-d charts using Html5 Canvas and CSS elements

If one opens a new website and wants to include some information related graphics, beautiful animation, image related processing, or games one should try learning about the HTML5 canvas element, an instant drawing surface utility in our very own webpage where one can make real time produced graphics, containing animations, videos, games, and all made without the use of a plug-in. Continue reading

Responsive Web Design

Let’s Learn to Build Responsive Navigation Menu in 40 Minutes

In today’s time making responsive websites have almost become a daily part of a developer’s life, as everyone want their sites to give optimum performance on all devices. However, one of the problematic parts in responsive design is to make a Responsive Navigation, and this is really a very crucial part of any website as it lets the users to navigate through all web pages of a site.

But don’t worry anymore as today with this tutorial we are going to learn building a responsive navigation menu in quick time. Though there are plenty of ways to create responsive navigation system as there are many jQuery plugins that makes it super easy.

However, we always advise against using any easy solution especially to beginners as they don’t help you learn the core of web development, and to ensure that you learn making a responsive navigation menu on your own, we have now come up with a detailed tutorial on building a simple yet responsive navigation from the scratch by using CSS3 media queries and a little pinch of jQuery to ensure it runs smoothly on all devices with small screen sizes like the smartphones.

So, let’s hit the ground zero now!

The HTML

In order to make our navigation menu work flawlessly we first need to add the ‘Meta Viewport’ inside the head tag. This Meta Viewport tag is essential in any responsive design you create to scale the webpage suitably inside any screen size, mainly in the mobile viewport.

Once you have added the meta viewport, add the following html codes for creating the navigation structure within the body tag.

In this code, as you can easily notice, we have created6 primary navigation menu links along with an additional link after them, all inside the HTML5 ‘nav’ tag. We will use this additional link to pull the navigation menu when gets hidden when viewed in a device with small screen size.

The CSS

If you are aware of HTML & CSS, you may be well aware of what CSS is used for. However, to all our new readers who are beginner in web development, we like to tell them the CSS is used for styling web pages. Now within our CSS file, we will add style to our navigation. As it’s just a simple navigation menu, we won’t be doing anything fancy. Therefore, we have added some elegant colors to decorate our navigation menu. However, you are always free to select and use any of the colors you desire.

Here, the nav tag that defines our menu bar will use full width of the browser window, therefore, set it to as 100%, whereas, for the ul tag, that contains our primary menu links will have set its width to 700px.

Now, to make our entire menu links come in one line, we have to make them float to the left, and set the display to inline. This will bring them all together laid horizontally side by side. However, here you must remember that floating an element also causes its parent to collapse.

If you might have noticed the HTML Markup thoroughly, you would have seen that for both the nav and ul tags, we have added the class with an attribute of clearfix. This comes handy to clear things around whenever we float elements inside it using the micro clearfix hack. So, now let’s add some more style rules in our CSS file.

As we have 6primary menu links in our navigation within a specified container bearing the maximum width of 700px, we now need to specify the width for each menu links. So let’s keep that width for all our links to100px.

Now we need to separate our menu links with a 1px right border, except leaving the last one. Though adding this 1px right border will expand the width for each menu link by 1px, so here we need to change the box-sizing model to border-box, this will keep the menu links remain with a width of 100px.

After that, we now need to set the color for the :hover or :active state. This will help users to identify what link they are on.

Once it’s done, we now need to hide the additional link, from the desktop version, we made in our HTML. Do that by using the display to none property.

Till now, we have only set the style for our navigation, so you’ll get nothing to see by resizing the browser window. So, let’s now move on to the next step where we would be adding CSS3 Media Queries.

The Media Queries

In responsive design, it’s the CSS3 media queries that defines how the web design will shift at defined breakpoints, which are generally set as of the most often used devices’ screen sizes.

As our navigation menu has a fix-width of 700px , we need to define its style when it is viewed in 700px or lower screen size. Technically, this will become our first breakpoint.

In this screen size, the 6 primary menu links will be divided into three rows containing two menu links displayed side by side, therefore, the ul‘s width here will become 100% of the browser window, and for the menu links it will be 50% of the width.

Now moving ahead, we need to define how our navigation is to be displayed when it is viewed on a screen size of 480px or lower, and this will be our second breakpoint.

In this screen size, the additional link we created in HTML will become visible, therefore, we will also assign a “Menu” icon on its right-side by using the ‘:after pseudo-element’, whereas to save the menu from covering entire vertical space available on the screen, our primary menu links will be hidden.

At last, when the screen size gets reduced to 320px or lower the navigation menu will be presented upright from top to bottom.

Great, now all is done! Almost! You can give it a try by resizing the browser window. Our navigation menu would now be able to adapt to the different screen sizes. Now let’s proceed ahead and integrate a pinch of jQuery to handle remaining things.

Showing The Menu with jQuery

Right now, the menu will still be concealed and can only be seen whenever it is required by clicking on the “Menu” link. And to achieve the effect, we will now use the jQuery slideToggle().

However, now when you increase your browser window’s size soon after viewing and hiding the menu on a smaller screen size, the menu will remain concealed, as the ‘display: none’ style produced by jQuery is still associated with the element.

Therefore, we now need to eliminate this style whenever the browser window gets resized, with this code;

Alright, that’s all we required to make a responsive navigation menu, you can now view your own navigation in any browser or smartphone. Additionally, we also suggest you to test it in a responsive design test tool, such as ipadpeek.com. This will help you view it in various width in one go.

If you liked our tutorial on building a responsive navigation, please share your feedback with us. Meanwhile, you can also subscribe to our blog or stay connected with us on our social networking profiles.

Mail Chimp VS Constant Contact

Mail Chimp Vs Constant Contact: Which Email Marketing Tool is more popular [Infographic]

Advertising emails are one of the fastest and cheapest advertising methods available to us. These emails, or newsletter as they are called, are a great way to maintain personalized contacts with customers and to promote your latest products, services, and schemes to a dedicated audience. However creating a user subscription list and managing these emails are tiring processes. Continue reading

website-testing-checklist

42 Essential Checks Before Launching Your Website

At XHTMLJunction, it’s been a decade since we are coding or developing websites from PSDs. To provide a pixel perfect website with perfect functionality to our clients, we follow a rigorous website testing process. We are sharing the same in a checklist format for users who are getting their PSD to HTML coded or are planning to launch their website. Users can also download or print the PDF format of the checklist. Continue reading

eNewsletter-testing-tools

Top 5 Best Email Newsletter Testing Tools

As per a report, enewsletter has a return of $40 for every $1 spent, and click-through rate of more than 5% with conversion rate of 4.15%. This explains why eNewsletter is the most favored channel to reach out, connect and to stay in touch with your prospective and current customers. Continue reading

ecommerce-shopping-cart-mistakes

Ecommerce Shopping Cart: The Mistakes Every Amateur Site Makes

Ecommerce keeps getting more and more popular, and now even smaller businesses are implementing online storefronts. Online stores allow you to sell to your target customers wherever they may be without the overhead of a physical storefronts or payroll for employees need to man the sales floor.

There are a lot of nuances to creating a quality ecommerce site, but among the most important- and most commonly poorly designed- is the shopping cart. It’s the last interface between your site and your customer, and it can make or break a good percentage your sales. Here are some common mistakes many small businesses make in creating ecommerce shopping carts, plus some tips on avoiding them in your own storefront:

1. Forgetting Function

The shopping cart should be little more than a collection of items that a user can add to or subtract from at any time. There’s nothing more frustrating than trying to update the quantity of an item you’re buying and having to circle back to the item’s page to make the necessary modifications, or than trying to take out an unwanted item from your cart and having to play hide and seek with the removal option. Users should be able to modify quantities and remove items right from the shopping cart page by making use of easily identifiable buttons.

2. Not Providing a Variety of Payment Options

The biggest rule of thumb is to always make it easy for your customers to give you money. PayPal is great but it’s not universally accepted and thus not everyone uses it. So make sure you’re taking credit cards on your ecommerce site. Yes, it costs money to accept credit card payments. However, you don’t always have to open a merchant account with the card providers or pay per transactions. There are a number of third party payment solutions that will allow you to do this, including PayPal’s merchant account option.

3. Mystery Totals

As part of your shopping cart’s basic functionality you should include a running total of the user’s purchase amount, plus an estimate of any taxes, shipping costs, and other fees. If your site offers sales and promotions, those discounts should be easy to identify within the total and should automatically update when items are placed in the cart- not once your customer gets to the payment screen. Having the order price skyrocket with the addition of hidden charges when it comes time to give credit card information is a good way to build distrust among your client base.

4. Long Checkouts

You’ve already spent time and money getting customers to your site, letting them browse your merchandise, and allowing them to select their purchases; converting those selections to actual sales should be a quick and painless process. The customer is trying to give you money- don’t make checking out difficult. Keep the number of screens as low as possible and don’t ask for more information than you absolutely need. Wherever possible, try to save your customer from retyping information. A checkbox that automatically fills in the billing details if they’re the same as shipping details, for example, is easy to implement and saves a lot of time in the checkout process.

5. Requiring Registration

Again- your customer is trying to give you money, so don’t make receiving that money conditional on registering on your site. A large number of potential buyers will be turned off by this and click away. Even if they do sign up, you run the risk of the user losing their login information when they visit again, causing customer service headaches. Its fine to present customers with the option of signing up for emails or creating an account on your site, but making it a requirement will probably end up costing you more sales in the present than it will earn you in the future.

6. Not Providing a Secure Site

You’re being trusted with sensitive payment information, probably in the form of credit card numbers. The least you can do for your customers is to provide a secure web page to minimize their fears of having their credit card information stolen. Now that ecommerce is so popular, people know to look for the “s” on the end of HTTP that indicates a secure site, or even the lock icon that appears in most browsers. Not having that security will put you at a disadvantage, and may cause some customers to rethink their purchases.

7. Unclear Delivery Options

This one may not seem like it’s a shopping cart problem but it is. It’s during checkout that most consumers first see the shipping options. Make it clear how long each option will take, who will be delivering it, and what the additional cost will be. Is your product a digital one that will be emailed to the buyer? Make sure you’re clear about that and when she can expect to see it in her Inbox. Clarity here will help you avoid having issues down the road when your customers are looking for their products and angrily calling your customer service number, because they didn’t understand the delivery terms.

8. Not Giving Users an Out

The best shopping carts remember who was there and what they had in their carts when they come back. Usually done through the use of cookies so a sign-in is not required, this allows customers who leave your site for any reason to pick right up where they left off. If you require the customer to remember what they had previously picked out and manually recreate the shopping cart, you may lose out on sales.

The best way to evaluate your shopping cart is to use it yourself. If you have trouble interacting with the items in your cart or navigating the checkout process, imagine how your customers will feel! You may never get a chance to complete an abandoned order, so don’t underestimate the importance of your shopping cart in the success of your ecommerce website.

Author Bio: Richard Larson is author and Brand Manager for GoPromotional Toys. He enjoys writing about business and marketing topics and ideas.

how-to-create-html5-contact-form

Creating an HTML5 Contact Form with jQuery Validation in Quick Time

Contact Form is one of the most essential parts of a website. It keeps your prospect customers connected with you forever and gives them access to communicate with you at anytime of the day. However, the contact form must have validated input fields which should also be marked properly to tell users about important fields. Additionally, the overall aesthetic appearance of a contact form also plays a big role in its success, and it should only have a few numbers of input fields so that users can fill it easily and in a short span of time. Therefore, your website’s contact form should never look dull and ugly, and must validate properly to keep the spammers away or else your email or database will be flooded with the spammy contact emails.

psd-to-html5-conversion-xhtmljunction

And if you don’t have an elegant and sleeky contact form on your website yet, that validates with jQuery, you need not to anymore, as with this blog post, we are going to tell you how you can make your own, HTML5 based contact form that validates with jQuery, in a shortest span of time. In the form that we will start building soon, we will be having 6 different input fields, namely; Your Name, Your Email, Your Phone, Your Website, Subject, and Your Message.

Here’s what we will be making today;

html5-contact-form

Before we begin to code this elegant contact form, we would like you to know you about the new HTML5 form elements, with which you can easily make a validated form without using jQuery. However, we would advise against it, as many old browsers don’t support HTML5 completely. Therefore, your form may not work properly on all browsers. Additionally, the client side validation can by bypassed easily therefore it is imperative to have a server side validation.

HTML5 New Form Input Types and Attributes

HTML5 Tutorial

With HTML5, many new form attributes have been introduced for the first time. These elements can easily enhance the form functionalities, and also helps to keep the HTML code to minimal extent. In addition to this, as there are plenty of new HTML5 form attributes, it won’t be possible to include all of them in this tutorial, so we have listed below the ones that are being widely used.

Input Types

Input type=”email”: You can use this while setting a form field for an email address. The benefit of using this input type is that the supporting browsers will be able to recognize if a user has entered a valid email address or not.

Input type=”url”: If your contact form has an input field asking users to fill their website address/url, then using this input type would be beneficial for you, as it will detect whether a user has entered a valid URL or not.

Input Attributes

  • Required: To ensure that your users submits all the necessary information that is required at your end, you can use this new input attribute as it restricts the users to submit a form until all necessary form fields are filled properly. However, this will not inform the users about the important form fields by default; therefore, you mustn’t forget to place a visual indication.

  • Placeholder: With this attribute, you can provide your users with the form fields hint so that the users will be able to fill the information accordingly. For example the format for phone number. Once the user clicks on any of the form field that holds a placeholder attribute, the placeholder disappears instantly, and it reappears when the cursor is moved out of it.

  • List: If you have to make a form field that should comprise of a data-list containing all possible options that your users may enter then using a list attribute would be a better choice. With this attribute, you can easily set the pre-defined values for a datalist tag.

Form Attributes

  • Autocomplete: This attribute can be placed with anyone of its values i.e., ‘on’ or ‘off’, either for the entire form or for a specific form field. When it is placed with the value ‘on’, the modern browsers can automatically complete the field values with the ones that the user has entered before.

  • Novalidate: If you don’t want your entire form or any of your form fields to check for validation, you can simply put this attribute.

Note: The New HTML5 attributes and input types do not work on Internet Explorer 9 and its older versions.

As we have explained the new HTML5 form input types and attributes, we can now move ahead to the form development part.

Here’s the HTML code for our contact form. We have displayed the code that comes under the body tag, and above that is pretty common, and only includes the doctype, Meta tags in the header, and linked CSS and JS files.

The HTML

basic-html5-contact-form

In the HTML5 code given above, we have done nothing new other than adding this kind of code line to all our form fields, which we will explain ahead, <–span class=”icon-user” aria-hidden=”true” data-icon=”&#128100″></span> Your Name <–span class=”required”>*</span>, and specifying a Placeholder attribute for all of them. Additionally, we have integrated some JavaScript code into it to execute the jQuery validation successfully.

The CSS

jQuery

The PHP Code

The Basic CSS Code

First of all let’s write the basic CSS code, like we have given above. With this code, our default margin is set to 0px, and the padding is also set to 0px. Then as you can see, we have set the border to none for the images and fieldset to get rid of the border that is coming in our basic HTML5 contact form (can be seen in the image given below). Though we haven’t used any images in developing this contact form, but we take it in our standard practice. After that, by using the :focus selector we have set the outline to none, this will help us get away with the border lines that may come while selecting any of the form fields. And to set the default font-family for all our text, we have used the body selector, and defined the fonts.

Now let’s create the striped background with the CSS and enhance the overall appearance of our contact form to make it look stylish and eye-catching. As you can see in our actual contact form image, we have a striped background, so let’s create that first. To create the striped background, we just need to specify the linear-gradient properties to the one element: .wrapper.

Let’s take a closer look at our background gradient code: “background: repeating-linear-gradient (-45deg, #15A35C, #15A35C 30px, #1973B8 30px, #C2B614 40px, #1973B8 40px, #15A35C 70px, #C2B614 70px, #15A35C 80px);”

Let’s define our gradient code in words to make it understandable, here’s what we are doing: creating a linear gradient with a -45° angle, the first strip is a green one, that goes from 0 to 30px, then add a blue strip from 30 to 40px, and the golden and blue one from 40 to 70px, then from 70px to 80px, the green one goes along with the golden one, and at last from 80px to 100px the green one goes again. And by stating a ‘repeating-linear-gradient’, we have repeated the whole gradient. Doing this, we have created a -45° striped “gradient” with a 30px green line, a 10px blue one, a 40px golden with blue one, and a 10px green with golden one, and again a 20px green that covers the rest 20% to make it 100%.

Styling H1 and Text Font

For the h1 tag, we have selected a font-family comprising of the fonts namely; the Palatino Linotype, Book Antiqua, Palation, and the Serif font. These fonts are pretty common, and come per-installed in the computer itself. In addition to this, we have set the font-size to 2em, to make it look stand out, and also set its font-weight to bold. To bring it to the center of the form, we have set the margin to -25px from the top, 0px from the left, 8px from the bottom, and 0px from the left.

Adding the Little Icons, with No Images

If you are a beginner in web development, you might be wondering what’s all this about? And how can anyone add an icon to an html element without using an image? However, this is nothing more than adding a simple line of code by using the icon fonts. In the concept of icon fonts, each letter of the alphabet is mapped with an icon, and generating a font using them.

html5-contact-form-with-jQuery

For our contact form we have used the entypo icon fonts, which are available for free, and can be used on commercial projects as well under certain conditions. To use this font, we have put the font files inside the font folder just like we save the CSS file inside the ‘css’ folder and Images inside an ‘image’ folder. Once all the font files are saved, using the @font-face technique, we have linked them in our CSS file.

Then by adding a small line of HTML code given above to every label in the HTML5 form file, and specifying the required icon’s no. as a value to the data-icon, we have successfully pointed the required icons. However, to give our font icons a unique style, such as setting their font size, and color, we have defined their properties inside the css. The noticeable thing in the CSS code for icon fonts, is the ‘:before’ selector, as we wanted all our icons to come before the HTML content. Similarly, you can also use the ‘:after’ selector to place the icons after your HTML content.

Isn’t that a simple yet effective technique to place icons without using images?

Styling the Send Button

As you can see in the HTML file, to make the send button we have used, the most common style that developers generally uses all around the world, input type=”submit”. A little bit of border-radius, adding the color, and setting the text margin and padding, all inside the CSS itself. Moreover, to differentiate the button on hover, we have only changed the color.

As you can see, our button has light pink color #db5984 in its background, along with a 2px white border, and a 15px of border-radius. And to make the border-radius work properly on all chrome, firefox, and opera, we have defined the vendor prefixes. However, the previous versions of Microsoft don’t support the vendor prefiex for border-radius, so the trick here is to use the pie.htc file, which can be found here.

The Thank You Message!

Presenting a successful form submission or confirmation message is a good practice that should always be followed. For our form too, we have used a customized Thank you message. For which we have used the h1 tag, which inherits the default h1 tag properties defined by us in the CSS. If you want you can change it in your css by denoting a new class or id to the tag inside the HTML.

jQuery Validation

First of all, we have created two variables namely; ‘isError’ and ‘errStr’. You can change these variable names to anything you want. As you can see, we have set the value for our first variable to False, and if the user tries to send the form after filling all the required details properly, it will validate the form, and doesn’t shoot up the error message just like we have defined with the second variable i.e., ‘errStr’.

Then to get rid of the unwanted whitespace from the error dialogue box, we have used the ‘$.trim()’ function before every jQuery code specified separately for each form field. In the above code, you may have noticed a ‘+’, this is used for concatenating the strings. In this case the current string will get associated with our second variable that we created above, but only if there’s an error related to the ‘Name’ input field, and to ensure that this string is displayed only whenever there’s an error, we have set our first variable’s value to true.

For other form input fields we have repeated this code, and changed their errStr variable message with the appropriate one, along with the input name, and value.

Alert and Form Submission

Here, we have set an alert for users to know that the form isn’t filled appropriately. And also set the form to submit if it finds no error.

As you may have already noticed in our form image, that we have only three input fields that are necessary for a user to fill, in order to submit the form. So we only needed to validate those three input fields. And here, with this code, we have defined what alphabets, special characters users can use for the respective fields.

Here we have set the form to submit via ajax in a post format, by using the mail_action.php file. And if the form gets submitted successfully, it will present the users with a success message that we have talked about earlier. The noticeable thing here is the usage of ‘.serialize()’ function, which is used to create a text string in standard URL-encoded notation.

With these lines of code, we ensure that once the user submits the form, all form fields get back to normal for other users, otherwise their might be an instance when the other user may see a pre-filled form. It’s very basic, nothing hi-fi, here by defining the input names for all validated fields, we have kept their values to nil.

The PHP Code for Mail-to-Action

To get the form data on email, we need to use the PHP, and for this form we have made a separate file named as mail_action.php. It’s again very basic, nothing unusual or extraordinary. In the second line, just define your email address, on which you want to receive the form data. Keep the third and fifth line as it is, as that’s with which you’ll be able to get the user’s email address, and his/her message.

However, you can edit the fourth line of code, and keep the subject whatever you want to.

The Email Format

This is how the message will be displayed on your email id. In this sequence, you’ll get the name, email, contact no., website URL (if any), subject, and message.

Here we have set the headers such as Multipurpose Internet Mail Extensions (MIME), the content type, and from. Then we have defined what we need to get or receive on email, like here we have set them to get us form subject, message, headers, and our email id that we can set inside the $to syntax. And to display the success message, we have set that to echo.

We hope this blog post may help you learn how to make elegant or classy HTML5 forms, and validate them using jQuery. If you like this blog post, please share your views with us via comment section provided below.