|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Friday, March 03, 2006Collecting Data Using HTML Forms (Chapter3)
HTML uses the Hypertext Transfer Protocol (HTTP) to transmit Web pages. When you enter a URL of a page in your browser, it sends an HTTP message to the server, requesting the desired page.This message is typically known as the Request message. If the desired page has a *.html or *.htm extension, the Web server simply retrieves the page from the server’s disk and sends it back to your computer (client) via a new HTTP message, known as the Response message. It is your browser that interprets the mark-up codes in the Response object and presents the page on your monitor.
In an HTML document, you can use an HTML form element to collect data from the user.Typically, other HTML elements like buttons, checkboxes, or textboxes are imbedded in an HTML form. It also provides an HTML Submit button in the form.With one click of the Submit button, the browser packages the user’s given data in a Request message and then sends it to the server. An HTTP message has two parts: the HTTP Header and the HTTP Body.Thus, the browser can package the user-given data in the Request object in one of two ways. It may augment the URL with the name-value pairs of submitted data. Alternatively, it can package the submitted data inside the body part of the Request message.Which of the alternative methods will it use? The answer depends on the specifications in the HTML form element.A typical form tag is shown in Figure 3.1.The Method parameter is used to specify the mode of data transmission. If it is “Get”, the browser sends the data in the header section of the HTTP message. If it is “Post”, the data are sent in the body section.The Action parameter can be used to request a specified html or other documents like .asp or .aspx files. Figure 3.1 Major Parameters (Attributes) of an HTML Form Element To demonstrate the data-passing mechanism using the Get method, we will present a simple example. Consider the Sample1.html document as shown in Figure 3.2, which is included on the CD that accompanies this book. In this code, we have included a HTML form named myForm. It has a Submit button, and a textbox.The user will enter a hobby and click the Submit button. On click of the Submit button, the browser will request the html document named Sample1.html and pass the submitted data to the server in the augmented URL. In this particular example, the browser will actually request the same html document (named Sample1.html). Figure 3.3 shows the URL of the requested form as submitted by the browser to the Web server.You will see that the browser has augmented the URL, and the new URL is http://ahmed2/Chapter3/sample1.html?txtHobby=Fishing. That means the data are submitted as a name=value pair in the URL itself.The first such pair is prefixed with a question mark. Figure 3.2 A Simple Data Collection HTML Form (Sample1.html) <!— Chapter3\Sample1.html —> <html><head></head><body> <form name="myForm" Action="Sample1.html" Method="Get"> Your Hobby? <input type="text" name="txtHobby" size=10> <input type="submit" Value="Submit"> </form></body></html> Figure 3.3 Submitting Data in the Augmented URL: Get Method If we specify Method=“Post” in the form tag, the data are packaged as namevalue pairs in the body section of the HTTP message. Unfortunately, we cannot have a peak inside the body section, and thus it cannot be shown. Once the data are submitted, what do we do with it? Well, that is where the server-side scripting comes into the scenario.We will briefly discuss the ASP.NET server-side processing in the next section. |
0 Comments:
Post a Comment
<< Home