FORMS FORMS n Forms are used to receive

  • Slides: 23
Download presentation
FORMS

FORMS

FORMS n Forms are used to receive information from the web surfer, such as:

FORMS n Forms are used to receive information from the web surfer, such as: their name, email address, credit card, etc. n Form fields are objects that allow the visitor to enter information - for example text boxes, drop-down menus or radio buttons.

Different fields/objects in a form n n n n n Text fields Password fields

Different fields/objects in a form n n n n n Text fields Password fields Radio button Check box Drop down list Selection list Text area Submit button Email to

Text fields password fields Option/radio button Check box Drop down list stream Commerce Science

Text fields password fields Option/radio button Check box Drop down list stream Commerce Science Arts Selection list Text area Submit button

FORMS n When a form is submitted, all fields on the form are being

FORMS n When a form is submitted, all fields on the form are being sent. n The <form> tag tells the browser where the form starts and ends. n You can add all kinds of HTML tags between the <form> and </form> tags. n To let the browser know where to send the content add the following properties to the <form> tag: n action=address method=post or method=get n The action specifies the URL to send the data to. The methods are the different methods for submitting data to the script. n "GET" should be used if and only if the form processing is a pure query form. There are, however, problems related to long URLs which make it necessary to use "POST" even for pure query cases.

Text Fields n <input> tag is used to tell the browser what type n

Text Fields n <input> tag is used to tell the browser what type n n n of field you want. The <input> has a few attributes that you should be aware of. type - Determines what kind of input field it will be. Possible choices are text, submit, and password. name - Assigns a name to the given field so that you may reference it later. size - Sets the horizontal width of the field. The unit of measurement is in blank spaces. maxlength - Dictates the maximum number of characters that can be entered.

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Name: <input type="text" size="10" maxlength="40" name="name">

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Name: <input type="text" size="10" maxlength="40" name="name"> Password: <input type="password" size="10" maxlength="10" name="password"> <input type="submit" value="Send"> </form> n Simply change the email address to your own and you will have set up your first functional form!

Radio Buttons n Radio buttons are a popular form of interaction. You may have

Radio Buttons n Radio buttons are a popular form of interaction. You may have seen them on quizzes, questionnaires, and other web sites that give the user a multiple choice question. n value - specifies what will be sent if the user chooses this radio button. Only one value will be sent for a given group of radio buttons n name - defines which set of radio buttons that it is a part of. Eg: shade and size.

HTML Code: n <form method="post" action="mailto: youremail@email. com"> What kind of shirt are you

HTML Code: n <form method="post" action="mailto: youremail@email. com"> What kind of shirt are you wearing? Shade: <input type="radio" name="shade" value="dark">Dark <input type="radio" name="shade" value="light">Light Size: <input type="radio" name="size" value="small">Small <input type="radio" name="size" value="medium">Medium <input type="radio" name="size" value="large">Large

Check Boxes n Check boxes allow for multiple items to be selected for a

Check Boxes n Check boxes allow for multiple items to be selected for a certain group of choices. The check box's name and value attributes behave the same as a radio button.

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Select your favorite cartoon characters. n

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Select your favorite cartoon characters. n <input type="checkbox" name="toon" value="Goofy">Goofy n <input type="checkbox" name="toon" value="Donald">Donald n <input type="checkbox" name="toon" value="Bugs">Bugs Bunny n <input type="checkbox" name="toon" value="Scoob">Scooby Doo

Drop Down Lists n Drop down menues are created with the <select> and <option>

Drop Down Lists n Drop down menues are created with the <select> and <option> tags. <select> is the list itself and each <option> is an available choice for the user.

HTML Code: n <form method="post" action="mailto: youremail@email. com"> College Degree? <select name="degree"> <option>Choose One</option>

HTML Code: n <form method="post" action="mailto: youremail@email. com"> College Degree? <select name="degree"> <option>Choose One</option> <option>Some High School</option> <option>High School Degree</option> <option>Some College</option> <option>Bachelor's Degree</option> <option>Doctorate</option> <input type="submit" value="Email Yourself"> </select> </form>

Selection Forms n Yet another type of form, a highlighted selection list. This form

Selection Forms n Yet another type of form, a highlighted selection list. This form will post what the user highlights. Basically just another type of way to get input from the user. n The size attribute selects how many options will be shown at once before needing to scroll, and the selected option tells the browser which choice to select by default.

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Musical Taste <select multiple name="music" size="4">

HTML Code: n <form method="post" action="mailto: youremail@email. com"> Musical Taste <select multiple name="music" size="4"> <option value="emo" selected>Emo</option> <option value="metal/rock" >Metal/Rock</option> <option value="hiphop" >Hip Hop</option> <option value="ska" >Ska</option> <option value="jazz" >Jazz</option> <option value="country" >Country</option> <option value="classical" >Classical</option> <option value="alternative" >Alternative</option> <option value="oldies" >Oldies</option> <option value="techno" >Techno</option> </select> <input type="submit" value="Email Yourself"> </form>

HTML Text Areas n Text areas serve as an input field for viewers to

HTML Text Areas n Text areas serve as an input field for viewers to place their own comments onto. Forums and the like use text areas to post what you type onto their site using scripts. For this form, the text area is used as a way to write comments to somebody. n Rows and columns need to be specified as attributes to the <textarea> tag. columns reflects how many characters wide the text area will be and the rows the height of the text box

Attribute of textarea n Wrap has 3 values. n wrap= "off" n "virtual" n

Attribute of textarea n Wrap has 3 values. n wrap= "off" n "virtual" n "physical" n Virtual means that the viewer will see the words wrapping as they type their comments, but when the page is submitted to you, the web host, the document sent will not have wrapping words. Physical means that the text will appear both to you, the web host, and the viewer including any page breaks and additional spaces that may be inputed. The words come as they are. Off of course, turns off word wrapping within the text area. One ongoing line. n

HTML Code: n <form method="post" action="mailto: youremail@email. com"> <textarea rows="5" cols="20" wrap="physical" name="comments"> Enter

HTML Code: n <form method="post" action="mailto: youremail@email. com"> <textarea rows="5" cols="20" wrap="physical" name="comments"> Enter Comments Here </textarea> <input type="submit" value="Email Yourself"> </form> n Also note that any text placed between the opening and closing textarea tags will show up inside the text area when the browser views it.

Submit n Generally, the submit button should be the last n n item of

Submit n Generally, the submit button should be the last n n item of your form. Here is a list of important attributes of the submit: In addition to adding the submit button, we must also add a destination for this information and specify how we want it to travel to that place. method - We will only be using the post functionality of method, which sends the data without displaying any of the information to the visitor. action - Specifies the URL to send the data to. We will be sending our information to a fake email address.

Send email from a form n <form action="MAILTO: someone@w 3 schools. com" method="post" enctype="text/plain">

Send email from a form n <form action="MAILTO: someone@w 3 schools. com" method="post" enctype="text/plain"> n n n n <h 3>This form sends an e-mail to W 3 Schools. </h 3> Name: <input type="text" name="name" value="yourname" size="20"> Mail: <input type="text" name="mail" value="yourmail" size="20"> Comment: <input type="text" name="comment" value="yourcomment" size="40"> <input type="submit" value="Send"> <input type="reset" value="Reset">

Reset button n When a visitor clicks a reset button, the entries are reset

Reset button n When a visitor clicks a reset button, the entries are reset to the default values. n Reset attributes name, value, align n The name setting adds an internal name to the button so the program that handles the form doesn't confuse the button with the other fields. The value setting defines what is written on the button. The align setting defines how the button is aligned. Valid entries are: TOP, MIDDLE, BOTTOM, RIGHT, LEFT, TEXTTOP, BASELINE, ABSMIDDLE, ABSBOTTOM. n The tabindex setting defines in which order the different fields should be activated when the visitor clicks the tab key.

IMAGE BUTTON n Image buttons have the same effect as submit buttons. When a

IMAGE BUTTON n Image buttons have the same effect as submit buttons. When a visitor clicks an image button the form is sent to the address specified in the action setting of the <form> tag. image name= src= align= border= width= height= vspace= hspace= tabindex=

<lable> n Defines a label to a control. If you click the text within

<lable> n Defines a label to a control. If you click the text within the label element, it is supposed to toggle the control.