Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Introducing forms: part 1

From: XHTML and HTML Essential Training

Video: Introducing forms: part 1

Forms in XHTML and HTML are how you provide interactions between a user and a web server. So they look like this. You have places where you can type things. You have buttons that you can press, and you have more places you can type things and more buttons you can press. There are different types of elements in a form and these are called widgets. So you can type text into a text widget, you can press radio buttons, and radio buttons are the kinds of buttons that are mutually exclusive.

Introducing forms: part 1

Forms in XHTML and HTML are how you provide interactions between a user and a web server. So they look like this. You have places where you can type things. You have buttons that you can press, and you have more places you can type things and more buttons you can press. There are different types of elements in a form and these are called widgets. So you can type text into a text widget, you can press radio buttons, and radio buttons are the kinds of buttons that are mutually exclusive.

In other words, I can only press one radio button at a time in a group of radio buttons, and they are groups together, so that you can have one choice out of several. Checkboxes are widgets that you can check and uncheck at will and they do not group together. So you can always check as many or as few as you like. Then this is a submit button. So when I'll click on this button, it will actually submit this data to the server, and then a program on the server takes over, and does whatever it's supposed to do with the data from the form. So there are a couple of things to understand here.

The most important is this is a two-part process. There is a front end and there is a back end. The front end is the XHTML or HTML that creates the form, and we have that here in this text editor here, so that you can see how to create these widgets. This course is about the front end. The back end is what the server does with the data once you submit it to the server. The back end is usually written in a program like Perl or PHP or something else. It accepts the data from the web browser, from the form that the user has filled out on the web browser using a protocol called CGI stands for Common Gateway Interface, and it's simply the very small, very simple specifications of how the browser talks to the server and passes back and forth this information that's in the form.

So this is about the front end. Now obviously the form is no good without some kind of a back end, and you need to understand that the process of installing a script on the back end is something that varies from server to server. I can give you the script, but I can't necessarily tell you how it installs on your server. The scripts that I have provided in the Exercise Files are written in Perl, and I have a separate course on Lynda.com about how to install Perl scripts on a server. Again, because all servers are different, it doesn't cover all possible situations, but it covers a lot of them.

And if you are interested in how to do that, you can take a look at that course using Perl with CGI, I believe it's called, and that will teach you how to do that. In the meantime for the purpose of testing your form, I have installed a small script on my server, and all it does is it gives you back exactly what you put into the form, so that you can experiment with your form fields, and you can at least design a form and follow along in this lesson. So I'm just going to go ahead here and click on Send, and you will see what that does is it just echoes back what you have you typed in the form fields and gives you some other information that probably doesn't mean a whole lot, but in the context of the server, it does.

So that is the there, so that you can follow along in this lesson. I've included that script in the Exercise Files, and I have also included a mail form script in the Exercise Files, which if you have somebody who knows how to install such things, you can install that on your server and use this form to actually send feedback to a given email address that you provide in the form. I'll talk a little bit about the CGI programs in the next lesson in this chapter, but this chapter is really about the front end. It's about how to do the forms in XHTML and HTML. So let's take a quick look at the form here, and what it does, and how it works.

This is form in XHTML, and it starts here with a form tag, and form tag has a couple of attributes. It has a method attribute, and it has an action attribute, these are required. Method = "post". There are two choices here. There is get and post, and we'll talk about those in a minute. The action attribute gives the location of the CGI script on your server in a URL. In this case it's my server, bw.org is my server, and it's this test.cgi, and again, you are welcome to use that just for the purpose of following along in this lesson.

Then we have the form elements. The forms elements are typically like this in an input tag. There are a few exceptions and we'll see that. The input tag here, in this case, it's type = "text" and that makes a text field. So we have here this little text box, one line of text, and that is done with this input type = "text" and name = "Name". We will talk in a moment about what this name attribute does. So here is another text box.

I'll scroll down here a little bit, and here is our radio buttons. So we have input type = "radio", name = " Retail", value = "Consumer" and checked = "checked" and then here is another radio button. Input type = "radio", name = "Retail", value = "Store". So you will notice that this one here says checked = "checked" and all that means is that. That's the button that is selected by default, and this name = "Retail", you will see, we used the same name in both of the radio buttons.

That's how they are grouped together. So you can only have one radio button selected at a time in a given group, and the group is defined by having the same name. So if they have the same name, only one of them at a time is going to be allowed to be selected. So we'll look at this in the browser, and here we have these two. Now I'm going to reset this form. If I just press Reload, it doesn't actually reset the form. It will reload the HTML, and it will show any changes here, but the data remains the same.

So if I want to actually reload the form, and reset it to its default position, I actually have to go up into the location bar and select it, and press the Enter key on my keyboard, which I'm going to do right here. That actually resets the form to its default state. Different browsers work a little bit differently, but most of them require something like that in order to reset a form. So now it's in its reset state, and you will see that the Consumer button is pressed, because I have this checked attribute here. If I take that out and save it, and then I'll reset the form again by going up to the title bar and pressing Enter.

Now you'll see that neither of the buttons are pressed. I need to press one. I don't have to. I can press neither of them. This is the only way to get neither of them to be selected. If I now select one, or select the other one, there is now no other way I can click outside of it. It doesn't unselect it. There is no other way to get none of them to be selected, but there is always going to be one at this point, and no more than one. So I'm going to go ahead and put that checked back in here, and save, and we'll go back and reset, and there we are.

Moving on, here are the checkboxes, and again, if I want to make one of these checked by default, I can use that checked = "checked" syntax. Here each of them has a separate name you will notice. The name attribute is different in each one of them, and you will see that the type = "checkbox" and that's what makes them checkboxes like here. You will see also that the text that's related to both the radio buttons and the checkboxes is separate. It's outside of the form element. It's done in the HTML. So I have word consumer here before the radio button for Consumer. I have the word retail stored here before the retail store, and all of these input elements are inline level elements.

So you go right in there with the text, and they just flow just like the text. So that's how that works. I just I want to show you, if I put in here checked = "checked", you will see that now this Hobbyist checkbox will be selected by default. I'll go back here to the browser, and I'm going to reset the form by selecting the location bar, and pressing the Enter key, and you see now that Hobbyist is checked by default. I can uncheck it if I want to, and I can check something else if I want to, but it's checked by default, because I had that checked = "checked" default in there, in the XHTML.

So I'll go ahead and take that out, and Save, and we'll move along here. We have another text box here. Input type = "text" and then we have one called textarea, and that's right here. Textarea is a container, and it creates this text area here, which you can type a lot of stuff into. You can type a lot of stuff in here. And if I just copy and paste that, you will see that eventually it gets a scrollbar after it fills up for a while.

So you can actually put up a lot of stuff in a text area. The dimensions of the textarea are specified here with cols = "30" and rows = "5". You can do different things within in CSS if you like. The contents of the container here, you'll notice it has a begin tag and an end tag is the default value. So if I put in here, This is the default for the textarea, and I click Save, and then I go in here and reset the form by selecting the location bar, and pressing Enter, you will see that now I get the default value in the textarea.

So that can be useful, if you want it to default or something. We'll go ahead and take that out for now, and Save. Finally, on this page you will see we have this button, which submits the form. It's the Send button down there at the bottom. This is type = "image". So a type = "image" acts like a submit button. Instead, you can say type = " submit" and I'll click Save here. Instead of this image here, we'll get a submit button, a normal submit button as we would see in our operating system.

So I'm just going to press Reload, and we'll see that the image now changes to this submit button that says Submit Query. That's the default text for that. You can change that with a value attribute. You can have it say value = "Label goes here", and if I save that, then the button will say label goes here when I reload. See, label goes here. So I'm going to go ahead and put this back the way that it was, and that's you create a normal submit button. Most people prefer the image buttons instead, so they can create their own image.

They can create their own button. Most people prefer to do it that way. You can even do things like creating rollovers using CSS and a lot of people like to do that. Those are the major elements available in a form. Those are the major Form widgets available.

Show transcript

This video is part of

Image for XHTML and HTML Essential Training
XHTML and HTML Essential Training

59 video lessons · 81411 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 10s
    1. Welcome
      1m 16s
    2. Using the exercise files
      1m 23s
    3. Choosing a text editor
      2m 31s
  2. 15m 46s
    1. Introducing HTML and XHTML
      2m 53s
    2. Understanding versions of HTML and XHTML
      2m 25s
    3. Exploring a simple XHTML page
      4m 47s
    4. Understanding the structure of an XHTML document
      2m 58s
    5. Understanding document containers
      54s
    6. Creating and using templates
      1m 49s
  3. 42m 4s
    1. Understanding how empty space is formatted in XHTML
      2m 42s
    2. Using paragraph tags
      2m 42s
    3. Aligning paragraphs
      2m 49s
    4. Understanding block-level and inline tags
      1m 24s
    5. Controlling line breaks and spaces
      5m 43s
    6. Formatting text with phrase element tags
      3m 28s
    7. Formatting text with font markup elements
      3m 24s
    8. Adding document structure with headings
      3m 25s
    9. Formatting quotations and quote marks
      2m 19s
    10. Preserving pre-formatted text
      1m 30s
    11. Selecting a typeface
      4m 33s
    12. Selecting a type size
      2m 11s
    13. Using ordered and unordered lists
      5m 54s
  4. 7m 48s
    1. Using inline images
      3m 17s
    2. Flowing text around an image
      2m 4s
    3. Breaking lines around an image
      2m 27s
  5. 22m 34s
    1. Working with hyperlinks
      7m 46s
    2. Using relative URLs
      3m 5s
    3. Specifying a base URL
      2m 4s
    4. Linking within a page using fragments
      4m 28s
    5. Creating image links
      5m 11s
  6. 22m 56s
    1. Introducing tables
      4m 37s
    2. Formatting tables with CSS
      8m 50s
    3. Aligning images with tables
      5m 7s
    4. Reviewing an alternative solution using CSS
      4m 22s
  7. 14m 31s
    1. Introducing frames
      7m 56s
    2. Hiding frame borders
      3m 15s
    3. Creating inline frames using iFrame
      3m 20s
  8. 20m 50s
    1. Introducing forms: part 1
      10m 37s
    2. Introducing forms: part 2
      7m 45s
    3. Using CGI with forms
      2m 28s
  9. 25m 42s
    1. Introducing CSS
      3m 11s
    2. Understanding levels of inheritance
      6m 10s
    3. Learning CSS syntax
      11m 23s
    4. Using units of measure in CSS
      4m 58s
  10. 1h 45m
    1. Comparing table layout and CSS layout
      1m 25s
    2. Exploring the finished web site
      2m 37s
    3. Building a document header
      8m 18s
    4. Placing a banner and a contact button
      8m 13s
    5. Laying out a main menu
      6m 55s
    6. Creating a layout template: main body area
      13m 31s
    7. Creating a layout template: sidebar area
      5m 17s
    8. Creating a layout template: footer content
      4m 46s
    9. Building a main home page: main body content
      11m 24s
    10. Building a main home page: sidebar content
      8m 52s
    11. Creating a page with a menu, graphics, and formatted links
      13m 26s
    12. Creating a page containing an ordered list
      6m 44s
    13. Creating a page containing video
      10m 45s
    14. Touring the finished site
      3m 45s
  11. 53s
    1. Goodbye
      53s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed XHTML and HTML Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.