LESSON 8: FORMSFormsForms allow you to add interactivity to your web documents by way of the <FORM> tag. With the form tag you can add to your web pages a guestbook, order forms, surveys, get feedback or whatever. The basic construction of a html form is this...
<FORM> begin a form
<INPUT TYPE=TEXT> Every input needs a NAME. <INPUT TYPE=TEXT NAME="ADDRESS"> When the user types in his address (for example 2 Victory Lane), it will become the input's value and be paired with ADDRESS so the end result after running it through Mailto Formatter will beADDRESS=2 Victory Lane. We can if we want, type in a VALUE. <INPUT TYPE=TEXT NAME="ADDRESS" VALUE="Victory Lane"> This will automatically pair the value Victory Lane with the name ADDRESS, unless the user changes it. Note- be sure to use quotes where I've specified. We can specify the size of the text input box. <INPUT TYPE=TEXT NAME="ADDRESS" VALUE="Victory Lane" SIZE=10> <INPUT TYPE=TEXT NAME="ADDRESS" VALUE="Victory Lane" SIZE=20> <INPUT TYPE=TEXT NAME="ADDRESS" VALUE="Victory Lane" SIZE=30> The default value is 20. If we want, we can specify how many characters a user can input. <INPUT TYPE=TEXT NAME="ADDRESS" SIZE=30 MAXLENGTH=10> Very similar to the TYPE=TEXT is the TYPE=PASSWORD. It is exactly the same, except it dispays *** instead of the actual input. The browser will send you the input, it just won't display it. <INPUT TYPE=PASSWORD> Remember that each <INPUT> must have a NAME. <INPUT TYPE=PASSWORD NAME="USER PASSWORD"> SIZE, VALUE, and MAXLENGTH modifiers/attributes work here also. By the way, a <TAG> tells the browser to do something.
Radio buttons allow the user to choose one of several options. Check Boxes allow the user to choose one or more or all of the options. <INPUT TYPE=RADIO NAME="POSITION"> Now add 2 more. <INPUT TYPE=RADIO NAME="POSITION"> Hmmm... I suppose we should put a line break after each one. <INPUT TYPE=RADIO NAME="POSITION"><BR> Note that each input has the same name. The reason will become apparent very shortly. Each of the Radio Buttons must be assigned a VALUE. <INPUT TYPE=RADIO NAME="POSITION" VALUE="PB"><BR> Now label each button. <INPUT TYPE=RADIO NAME="POSITION" VALUE="A"> hp<BR> You can also modify these labels with other html tags if you wish. Essentially your Radio Buttons are done. You can tidy things up by adding a statement above the buttons, and if you want, choose a default selection (optional). What is your position within the company?<BR> The user of course can only choose 1 option. Their choice will be returned to you as the name/value pair POSITION=A (or whichever they pick). Building Check Boxes is pretty much the same thing. Start with this. <INPUT TYPE=CHECKBOX NAME="A"> Add 3 more, but this time give each one a different NAME. (Also add in line breaks if you want) <INPUT TYPE=CHECKBOX NAME="A"><BR> Each Check Box gets the same VALUE. <INPUT TYPE=CHECKBOX NAME="A" VALUE="YES"><BR> Note- For Check Boxes the NAME changes and the VALUE stays the same and with Radio Buttons, the VALUE changes but the NAME stays the same. Don't feel bad, my simple mind still gets confused.
OK, let's label each box. <INPUT TYPE=CHECKBOX NAME="A" VALUE="YES"> hp<BR> And lastly, you may want to add a little something above your check boxes and maybe pick a couple defaults. What positions do you occupy within the company?<BR> The user can choose 1, 2, none or all of the options. Their choices will be returned to you as the name/value pairs...
A=YES YOUR HTML PAGE !!!Add this as a feedback.htm form.<html> <body background="bgimage.png" bgcolor=#FFFFFF> <center><h1>Feedback Form</h1></center> <br> <form> <b>My name is: </b><input type=text name="name"> <p> <b>I work as a:</b><br> <input type=radio name="position" value="Developer" checked>Developer<br> <input type=radio name="position" value="ProjMan">Project Manager<br> <input type=radio name="position" value="TechMan">Technical Manager<br> <input type=radio name="position" value="NOTA">None of the above </p> <p> <b>When it comes to web browsers:</b><br> <input type=checkbox name="Netscape" checked>I use Netscape Navigator<br> <input type=radio name="NetscapeVer" value="2.0">version 2.0<br> <input type=radio name="NetscapeVer" value="3.0" checked>version 3.0<br> <input type=checkbox name="IExplorer">I use Microsoft Internet Explorer<br> <input type=radio name="IEVer" value="2.0">version 2.0<br> <input type=radio name="IEVer" value="3.0">version 3.0<br> </p> </body> </html> Save the file.
Pull Down and Scrolling ListsThe next type of input is a Pull Down List. With this type you use <SELECT> instead of <INPUT> and it has a closing tag. <SELECT> Don't forget to give it a name. <SELECT NAME="POSITION"> Next add a few options. <SELECT NAME="POSITION"> And give each <OPTION> a VALUE. <SELECT NAME="POSITION"> The default option is the one that is listed first. We can specify a default other than the first option in the list. <SELECT NAME="POSITION"> A Scrolling List is very similar in construction to a Pull Down List. We'll add a few more options first. Then, all we do to turn it into a Scrolling List is add a SIZE attribute to the <SELECT> tag. <SELECT NAME="POSITION" SIZE=4> The SIZE is simply how many options show in the window. Again, the default value is the first <OPTION>, and again we can change that by selecting one. <SELECT NAME="POSITION" SIZE=4> TextareaA very useful type of input is <TEXTAREA>.<TEXTAREA NAME="COMMENTS"> You control the size of the box like so... <TEXTAREA NAME="COMMENTS" ROWS=6 COLS=50> ROWS is the height, COLS is the width. A good attribute to include in <TEXTAREA> is WRAP. Some browsers do not understand it, but if that's the case, they will just ignore it. Go ahead and type in the boxes... <TEXTAREA NAME="COMMENTS" ROWS=3 COLS=30 WRAP=VIRTUAL> WRAP=VIRTUAL means that the text in the box wraps, but it is sent as one long continuous string. <TEXTAREA NAME="COMMENTS" ROWS=3 COLS=30 WRAP=PHYSICAL> WRAP=PHYSICAL means that the text in the box wraps, and it is sent that way too. <TEXTAREA NAME="COMMENTS" ROWS=3 COLS=30 WRAP=OFF> This is the default. YOUR FIFTH HTML PAGE !!!Open Notepad, and add the following. <html><body background="bgimage.jpg"> <center><h1>Feedback Form</h1></center> <br> <form> <b>My name is: </b><input type=text name="name"> <p> <b>I work as a:</b><br> </p> <p> <b>When it comes to web browsers:</b><br> . </p> <b>I rate your site as:</b><br> <select name="Rating"> <option value="Wow">Wow! How did you do it? <option value="good">Really good <option value="interesting">Interesting <option value="hmmm">Hmmm - seen better <option value="tryagain">Try again bud! </select> </p> <p> <b>Comments:</b><br> <textarea name="comments" rows="6" cols="50" wrap="physical"> </textarea> </p> </body> </html> Save the file. Submit and Reset ButtonsLast on the list are the SUBMIT and RESET buttons. They really are very simple... <INPUT TYPE=SUBMIT> SUBMIT of course, sends the data and RESET, clears the form. <INPUT TYPE=RESET> We can easily change what the buttons say. <INPUT TYPE=SUBMIT VALUE="Send it away Ray!"><BR> If necessary, the SUBMIT button can also have a NAME. You would need this if, for whatever reason, you had more than one SUBMIT button. Next we must tell the browser where to send the data we gather and how to send it. There are two basic things you can do: Note- Microsoft's Internet Explorer 3.0 does not support mailto forms. When you try to submit the information, the new mail message window pops up. Explorer does however support forms sent to a CGI script. <FORM METHOD=POST ACTION="mailto:eidzeiaiti@gmail.com" ENCTYPE="application/x-www-form-urlencoded"> When you put a mailto form on your page and someone sends you information, you'll notice that it is sent with a default Subject. If your visitor was using Netscape you'd get the default Subject "Form posted from Mozilla". Other browsers might send "Form Response", etc.
You can change this by editing what's in the <FORM> tag as follows... <FORM METHOD=POST ACTION="mailto:eidzeiaiti@gmail.com?subject=Company feedback form" ENCTYPE="application/x-www-form-urlencoded"> YOUR FIFTH HTML PAGE !!!Open Notepad, and add the following.<html> <body background="bgimage.jpg"> <center><h1>Feedback Form</h1></center> <br> <form method=post action="mailto:YOUREMAILADDRESS?subject=Feedback" enctype="text/plain"> <b>My name is: </b><input type=text name="name"> <p> <b>I work as a:</b><br> </p> <p> <b>When it comes to web browsers:</b><br> </p> <b>I rate your site as:</b><br> </p> <p> <b>Comments:</b><br> </p> <p> <input type="submit" value="Send it!"><br> <input type="reset" value="Clear it!"> </p> </body> </html> Save the file. |
Tuesday, 27 November 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment