Ryan's District
November 21, 2008, 11:34:05 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: You are not allowed to view links.
Register or Login
How to Unlock Nokia mobile Phones

You are not allowed to view links.
Register or Login
Request any TV Show / series / Episodes / movie and we will get it for you for free

 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Real Form Example  (Read 3283 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 06, 2006, 03:40:57 PM »

Now, we will look at a real HTML form example.
We will first look at the HTML form that will be used in this example: The HTML form below asks for the user's name, country, and e-mail address. This information will then be written to an XML file for storage.
"customers.htm":
<html><body><form action="saveForm.asp" method="post"><p>Enter your contact information</p>First Name: <input type="text" id="fname" name="fname">
Last Name: <input type="text" id="lname" name="lname">
Country: <input type="text" id="country" name="country">
Email: <input type="text" id="email" name="email">
<input type="submit" id="btn_sub" name="btn_sub" value="Submit"><input type="reset" id="btn_res" name="btn_res" value="Reset"></form></body></html>
The action for the HTML form above is set to "saveForm.asp". The "saveForm.asp" file is an ASP page that will loop through the form fields and store their values in an XML file:
<%dim xmlDocdim rootEl,fieldName,fieldValue,attIDdim p,i'Do not stop if an error occursOn Error Resume NextSet xmlDoc = server.CreateObject("Microsoft.XMLDOM")xmlDoc.preserveWhiteSpace=true'Create a root element and append it to the documentSet rootEl = xmlDoc.createElement("customer")xmlDoc.appendChild rootEl'Loop through the form collectionfor i = 1 To Request.Form.Count  'Eliminate button elements in the form  if instr(1,Request.Form.Key(i),"btn_")=0 then    'Create a field and a value element, and an id attribute    Set fieldName = xmlDoc.createElement("field")    Set fieldValue = xmlDoc.createElement("value")    Set attID = xmlDoc.createAttribute("id")    'Set the value of the id attribute equal to the name of    'the current form field    attID.Text = Request.Form.Key(i)    'Append the id attribute to the field element    fieldName.setAttributeNode attID    'Set the value of the value element equal to    'the value of the current form field    fieldValue.Text = Request.Form(i)    'Append the field element as a child of the root element    rootEl.appendChild fieldName    'Append the value element as a child of the field element    fieldName.appendChild fieldValue  end ifnext'Add an XML processing instruction'and insert it before the root elementSet p = xmlDoc.createProcessingInstruction("xml","version='1.0'")xmlDoc.insertBefore p,xmlDoc.childNodes(0)'Save the XML filexmlDoc.save "c:\Customer.xml"'Release all object referencesset xmlDoc=nothingset rootEl=nothingset fieldName=nothingset fieldValue=nothingset attID=nothingset p=nothing'Test to see if an error occurredif err.number<>0 then  response.write("Error: No information saved.")else  response.write("Your information has been saved.")end if%>
Note: If the XML file name specified already exists, it will be overwritten!
The XML file that will be produced by the code above will look something like this ("Customer.xml"):
<?xml version="1.0" ?><customer>  <field id="firstName">    <value>Hege</value>   </field>  <field id="lastName">    <value>Refsnes</value>   </field>  <field id="country">    <value>Norway</value>   </field>  <field id="email">    <value>mymail@myaddress.com</value>   </field></customer>
Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
« on: October 06, 2006, 03:40:57 PM »

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 1.596 seconds with 31 queries.

Google visited last this page Today at 11:50:16 AM