Using Forms in HTML
We chose Server Intellect for its cloud hosting, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.
Step 1.
The first thing we’ll need to do is create a form within our HTML page. This is a very simple task, and looks a lot like the tags we’ve previously learned about. Here’s what the form tag should look like:Notice that the form tag has an attribute called “action”. This is a required attribute of the form element. Normally, instead of a # character in the quotes (which is simply a placeholder); we would use the name of a file that would handle our form. For instance, we may have a PHP form that sends out an email, in which case our “action” might be “index.php”. Let’s take a look at some of the elements we can add to our form.
Step 2.
Form elements are typically called “input” elements. In fact, the tag is the tag used to denote most of the common form elements. Let’s go ahead and add a regular text box into our page. Here’s what the HTML should look like:<body>
<form action="#">
Text box: <input type="text" />
</form>
</body>
What if I don’t want to display what the user is typing? I don’t want to expose a user’s password to the entire world, for example. Luckily, there’s a rather hand solution, and it only requires that we use a different type of input; a password input. Let’s add a password input to our page now:
<body>
<form action="#">
Text box: <input type="text" /> <br />
Password: <input type="password" /> <br />
</form>
</body>
The next element on the list is called the Radio Button. When you need a user to be able to select a single item from a group (and ONLY a single item), radio buttons are the way to go. When radio buttons are placed within the same group, only one of them can be selected at a time. Let’s go ahead and add 3 radio buttons to our form. Take special notice of the “name” and “value” attributes we’ve given to each:
<body>
<form action="#">
Text box: <input type="text" /> <br />
Password: <input type="password" /> <br />
Radio button: <input type="radio" name="group1" value="alien" /> alien <br />
Radio button: <input type="radio" name="group1" value="yeti" /> yeti <br />
Radio button: <input type="radio" name="group1" value="zombie" /> zombie <br />
</form>
</body>
Want a user to be able to select multiple items at once? There’s an elegant solution for that as well. That solution is the Check Box. This element also takes a value attribute, and will pass that value to the “action” file. Let’s add 3 check boxes to our form now:
<body>
<form action="#">
Text box: <input type="text" /> <br />
Password: <input type="password" /> <br />
Radio button: <input type="radio" name="group1" value="alien" /> alien <br />
Radio button: <input type="radio" name="group1" value="yeti" /> yeti <br />
Radio button: <input type="radio" name="group1" value="zombie" /> zombie <br />
Check box: <input type="checkbox" value="ninja" /> Ninja <br />
Check box: <input type="checkbox" value="samurai"/> Samurai <br />
Check box: <input type="checkbox" value="sensei" /> sensei <br />
</form>
</body>
We used over 10 web hosting companies before we found Server Intellect. Our new server with cloud hosting,was set up in less than 24 hours. We were able to confirm our order over the phone. They responded to our inquiries within an hour. Server Intellect’s customer support and assistance are the best we’ve ever experienced.
Finally, we’ll need our users to be able to submit the form to us so that we can collect the data. Recall that the “action” attribute for our form is just a placeholder right now – but a “Submit Button” would allow all of our form values to be submitted to the action attribute. Let’s add the Submit Button to our form now:<body>
<form action="#">
Text box: <input type="text" /> <br />
Password: <input type="password" /> <br />
Radio button: <input type="radio" name="group1" value="alien" /> alien <br />
Radio button: <input type="radio" name="group1" value="yeti" /> yeti <br />
Radio button: <input type="radio" name="group1" value="zombie" /> zombie <br />
Check box: <input type="checkbox" value="ninja" /> Ninja <br />
Check box: <input type="checkbox" value="samurai"/> Samurai <br />
Check box: <input type="checkbox" value="sensei" /> sensei <br />
Submit button: <input type="submit" value="submit" />
</form>
</body>
The design view of the project should appear like the following image:

Notice that the browser will refresh when you try and submit the form. This is because it’s assuming we have an “action” file to send it to, which for this tutorial, we do not. We discuss action files in a future tutorial.
A Few Last Words
HTML forms are essential for collecting information from users on your website, and knowing how to implement them properly is a skill that’s sure to come in handy for you future projects. Join us next time for additional HTML tutorials!button
