Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Probably the most common form element is the text field. The text field allows users to input text for form submittal. There are three flavors of the text field. There is the input text field, the password text field, and the text area element. Now the input text field is used for capturing a single line of text, and basically it's used for names, addresses, and anything else that the user might type themselves that fits on a single line. The password text field is just the same as the input text field; only, it hides the text being typed by the user.
Otherwise, it submits text just like any other text field. The text area field allows users to submit as many lines of texts as they require and is primarily used for commenting or contact forms where the user needs to submit a request. Although you can select a text element in Dreamweaver and then change it from one text field type to another in the Properties Inspector, Dreamweaver gives us individual icons to insert the text element of choice so the process is extremely simple. So again, I'm in the request.htm file, this time from the 10_06 directory, and if you're looking at the form, I think you can tell there's something different about it right off the bat.
Remember earlier when we reviewed the form structure, all of our form elements were going to be contained within list items. Now by containing all of our form elements in an unordered list, that's just going to give us a little bit more organization, a little bit more structure to our form. It's going to let other user agents know that those form elements are related to each other and it also helps us style our forms because it gives us that extra styling hook. So there is a lot of benefit from structuring your forms this way. Now whenever I build a form, this is kind of how I do it. I plan the form out, I plan what's going to go where, and then what I'll do is I'll just go ahead and create my unordered list or lists, and then I'll just put placeholders where my form element goes.
Now the reason that I do that, it's twofold. One is it helps me understand kind of like how my list is going to look on the page and how elements are going to relate to each other, but it also helps me build a form visually inside Dreamweaver. It's very, very difficult to select existing form elements in and then wrap them in a list. You almost have to do that by hand. It's also very difficult to start a list item with nothing in it and then start placing form element, I mean it's, Dreamweaver doesn't like that all that much either. So typically what I'll do is this: create a list, put placeholder elements in it, and then replace those placeholder elements over the time that I'm building the form with the form elements themselves.
So the first thing we're going to do is just that. I'm going to highlight the Name Placeholder text. I don't want to get rid of the entire list item; just the text itself, so I'm going to highlight the text and hit Delete. Notice that I'm still inside the list item. The next thing I'm going to do is go up to my Forms objects and I'm going to go right here to the Text Field. When I click on that, again, we get the Input Tag Accessibility Attributes for this. For the ID, I'm going to give it name, all lowercase, and then for Label, I'm going to give it name with an uppercase. Remember, Label is what the user of the form will actually see; the ID is the value that's going to be submitted along with that.
So essentially, once this form is submitted, it will have a name/value pair that'll say something like name= and then whatever somebody typed in. I'm again going to attach the label tag using the for attribute, I'm going to make sure that the Position is Before the form item which is the default, and I'm going to give it a Tab Index of 10. I really like doing Tab Indexes of 10 like 10, 20, 30, 40, 50 because if you ever have to go back and modify your form a little bit later on, you're not having to renumber every single thing in the form; you have a little bit of wiggle room. So if I need to put a form element between the first and second items, I can use 11, 12, 13 and do that sort of thing. All right! I'm going to go ahead and click OK, and there is my first initial text field.
The next thing I'm going to do is I'm going to highlight the Email Placeholder, get rid of that, and go through the process one more time. This time, of course, the ID is going to be a little different. The IDs need to be unique. If you've used a name already once, you can't use it again for an ID. And then for Label, I'm going to type in Email. Tab Index for that is going to be 20, and I'm going to click OK. So you can see, these are really, really simple to do. Now because of the fact that we sort of have placeholders in place for our form, we can jump around the form and start creating different regions without having to go in order.
So what I'm going to do is scroll down and find this little Comments Placeholder, highlight that and delete the text. And then I'm going to go up to my Form objects and this time I'm going to click on the text area. So it's the fourth icon from the left here, Text Area. And I get a very similar looking Input Tag Accessibility Attributes. It's almost exactly the same as the Text Input. And for that one, what I'm going to do is the ID for that is going to be comments and the Label is going to be Additional Comments. So that of course can be as long of a literal string as you need it to be.
Now this one's Tab Index is going to be a little higher, it's going to be 130, and the reason I know that is because I already have all those placeholders in place. I'm going to go ahead and click OK on that one as well. Now any time you place a form element on the page, you can also select that form element and take a look at the properties within the Properties Inspector. You can see that for example, any time you select a Text Input Field whether it be a text area or an actual input, you have the ability to switch it from Single line, Multi line, and a Password. You'll note for example, there's no Password icon up here in the Form elements.
You'll need to go ahead and set that using the Properties Inspector. You can also apply Classes, you can type in attributes that are specific to that element. Now there are all sorts of values that you can change here. Now I do want to mention something here about HTML5. When I click on the Email form element, I will notice down there that we don't have multiple types of inputs. One of the things that has changed in HTML5 is we now have different input types that we can use for text input. You can use just regular text, you can also do things like URLs if it's going to be a link, you can also specify email, and that's exactly what we're going to do here.
So the quickest and the easiest way to do this is to use the Tag Selector. So I'm going to make sure this text input field is selected, I'm going to hit Ctrl+T or Command+T; that's going to bring up my Tag Selector, and there is the HTML code. And what I'm looking to change is the type attribute. So right now, the type is text. I'm going to change that to email. That does a lot of things. You'll notice that in code hinting, Dreamweaver does support these new form elements. This can actually do a few things for us. Number one, it makes your form a little more future-friendly, because as user agents and browsers begin to support different input types, your forms will already be constructed that way.
But there are actual real world tangible benefits from doing this right now. If somebody were to fill this form out, for example, on a mobile device, when they click into the input type of email, their keyboard is going to change and it's going to have the At symbol. So there are certain things that user interfaces are doing right now to assist people when they're using these types of form elements. All right! I'm going to go ahead and hit Enter to commit to that change and I'm going to go ahead and save my file. So our form is well on its way. While this is not all of the fields that are necessary for our form, it is a good start and it should give you an idea of how easy it is to place text fields in your form.
From this point forward, all that remains is to consider the information that we need to collect from our user and which form elements meet the requirement for collecting that data.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.