html form that saves to xml - need to have dynamic name

  • dogbert
  • Novice
  • Novice
  • User avatar
  • Posts: 28
  • Loc: Tacoma, WA

Post 3+ Months Ago

Hello all, I'm trying to create an xml file from the data given from an HTML form. the issue I'm running into is naming the xml file, I want to create the file name dynamicly by using the value from a select box and text feild in the form but cant get it to work with the script I've got to make the xml file, thus Please help. (if you have any sugestions as to a better way of doing this other then what I have feel free to let me know. my exspriance in this is limited.)

HTML FORM:
Code: [ Select ]
 
Line number On/OffCode: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>XML MAKER</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" media="screen" type="text/css" href="../css/index_style.css" />
</SCRIPT>
</head>
<body>
<div id="head">
  <center><img src="..\images\dd_logo.jpg" width="300px" height="100px" /></center>
</div>
<div id="data">
  <center>
  <form name="DailyD" action="createxml.asp" method="post">
  <h1>
  <table border="0px" width="600px" cellspacing="0" cellpadding="0">
  <tr><td colspan="3">N, D, & L</td></tr>
  <tr><td>Name: </td><td><select id="name" name="name" class="formlook">
      <option value="nameone">nameone</option>
      <option value="nametwo">nametwo</option>
      <option value="namethree">namethree</option>
      <option value="namefour">namefour</option>
      <option value="namefive">namefive</option>
      <option value="namesix">namesix</option>
      </select></td><td> </td></tr>
  <tr><td>Date: </td><td><input id="date" name="date" type="text" class="formlook" /></td><td>(ex: "090212" = Febuary 12, 2009)</td></tr>
  <tr><td>Location: </td><td><input id="bldg" name="bldg" type="text" class="formlook" /></td><td> (ex: "BLDG 36 - 4407")</td></tr>
  </table>
  </h1>
  <br />
  <h3>
  <table border="0px" width="600px" cellspacing="0" cellpadding="0">
  <tr><td colspan="3">TIME</td></tr>
  <tr><td>Spent On</td><td>Hours</td><td rowspan="5">Time Notes:<br /><textarea rows="5" cols="30" id="tn" name="tn">......</textarea></td></tr>
  <tr><td>Site Services:</td><td><input id="ssh" name="ssh" type="text" class="formlook" /></td></tr>
  <tr><td>Side Project:</td><td><input id="sph" name="sph" type="text" class="formlook" /></td></tr>
  <tr><td>Other:</td><td><input id="oh" name="oh" type="text" class="formlook" /></td></tr>
  <tr><td>Successfull Day?</td><td><input id="sd" name="sd" type="text" class="formlook" /></td></tr>
  </table
  </h3>
  <br />
  <h5>
  <table border="0px" width="600px" cellspacing="0" cellpadding="4">
  <tr><td colspan="2">NOTES</td></tr>
  <tr><td>support:</td><td><textarea rows="8" cols="40" id="ssn" name="ssn">......</textarea><br /></td></tr>
  <tr><td>project:</td><td><textarea rows="8" cols="40" id="spn" name="spn">......</textarea><br /></td></tr>
  <tr><td>Other:</td><td><textarea rows="8" cols="40" id="on" name="on">......</textarea><br /></td></tr>
  </table>
  </h5>
  <table>
  <tr><td><td><center><input type="submit" id="btnSub" name="btnSub" value="Submit">&nbsp;&nbsp;&nbsp;<input type="reset"></center></td></tr>
  <tr><td colspan="2">PLEASE DONT SEND, THIS IS STILL IN TEST MODE AND WILL NOT FUNCTION CORRECTLY!!!!</td></tr>
  </table>
  </center>
  </form>
</div>
</body>
</HTML>
 
  1.  
  2. Line number On/OffCode: Select all
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <title>XML MAKER</title>
  7. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  8.   <link rel="stylesheet" media="screen" type="text/css" href="../css/index_style.css" />
  9. </SCRIPT>
  10. </head>
  11. <body>
  12. <div id="head">
  13.   <center><img src="..\images\dd_logo.jpg" width="300px" height="100px" /></center>
  14. </div>
  15. <div id="data">
  16.   <center>
  17.   <form name="DailyD" action="createxml.asp" method="post">
  18.   <h1>
  19.   <table border="0px" width="600px" cellspacing="0" cellpadding="0">
  20.   <tr><td colspan="3">N, D, & L</td></tr>
  21.   <tr><td>Name: </td><td><select id="name" name="name" class="formlook">
  22.       <option value="nameone">nameone</option>
  23.       <option value="nametwo">nametwo</option>
  24.       <option value="namethree">namethree</option>
  25.       <option value="namefour">namefour</option>
  26.       <option value="namefive">namefive</option>
  27.       <option value="namesix">namesix</option>
  28.       </select></td><td> </td></tr>
  29.   <tr><td>Date: </td><td><input id="date" name="date" type="text" class="formlook" /></td><td>(ex: "090212" = Febuary 12, 2009)</td></tr>
  30.   <tr><td>Location: </td><td><input id="bldg" name="bldg" type="text" class="formlook" /></td><td> (ex: "BLDG 36 - 4407")</td></tr>
  31.   </table>
  32.   </h1>
  33.   <br />
  34.   <h3>
  35.   <table border="0px" width="600px" cellspacing="0" cellpadding="0">
  36.   <tr><td colspan="3">TIME</td></tr>
  37.   <tr><td>Spent On</td><td>Hours</td><td rowspan="5">Time Notes:<br /><textarea rows="5" cols="30" id="tn" name="tn">......</textarea></td></tr>
  38.   <tr><td>Site Services:</td><td><input id="ssh" name="ssh" type="text" class="formlook" /></td></tr>
  39.   <tr><td>Side Project:</td><td><input id="sph" name="sph" type="text" class="formlook" /></td></tr>
  40.   <tr><td>Other:</td><td><input id="oh" name="oh" type="text" class="formlook" /></td></tr>
  41.   <tr><td>Successfull Day?</td><td><input id="sd" name="sd" type="text" class="formlook" /></td></tr>
  42.   </table
  43.   </h3>
  44.   <br />
  45.   <h5>
  46.   <table border="0px" width="600px" cellspacing="0" cellpadding="4">
  47.   <tr><td colspan="2">NOTES</td></tr>
  48.   <tr><td>support:</td><td><textarea rows="8" cols="40" id="ssn" name="ssn">......</textarea><br /></td></tr>
  49.   <tr><td>project:</td><td><textarea rows="8" cols="40" id="spn" name="spn">......</textarea><br /></td></tr>
  50.   <tr><td>Other:</td><td><textarea rows="8" cols="40" id="on" name="on">......</textarea><br /></td></tr>
  51.   </table>
  52.   </h5>
  53.   <table>
  54.   <tr><td><td><center><input type="submit" id="btnSub" name="btnSub" value="Submit">&nbsp;&nbsp;&nbsp;<input type="reset"></center></td></tr>
  55.   <tr><td colspan="2">PLEASE DONT SEND, THIS IS STILL IN TEST MODE AND WILL NOT FUNCTION CORRECTLY!!!!</td></tr>
  56.   </table>
  57.   </center>
  58.   </form>
  59. </div>
  60. </body>
  61. </HTML>
  62.  



createxml.asp

Code: [ Select ]
 
Line number On/OffCode: Select all
<%
 
Function ConvertFormtoXML(strXMLFilePath, strFileName)
 
 Dim objDom
 Dim objRoot
 Dim objField
 Dim objFieldValue
 Dim objattID
 Dim objPI
 Dim x
 
 Set objDom = server.CreateObject("Microsoft.XMLDOM")
 objDom.preserveWhiteSpace = True
 
 Set objRoot = objDom.createElement("debrief")
 objDom.appendChild objRoot
 
 For x = 1 To Request.Form.Count
 
  If instr(1,Request.Form.Key(x),"btn") = 0 Then
 
   'Create element "field".
   Set objField = objDom.createElement("field")
 
   'Create attribute "id".
   Set objattID = objDom.createAttribute("id")
 
   'Set the value of attribute
   objattID.Text = Request.Form.Key(x)
 
   'append the id attribute to field element.
   objField.setAttributeNode objattID
 
   'Create a new element, "field_value".
   Set objFieldValue = objDom.createElement("field_value")
 
   'value of field_value element equal to value of current field.
   objFieldValue.Text = Request.Form(x)
 
   'Append field element as child of root.
   objRoot.appendChild objField
 
   'Append field_value element as child of field elemnt.
   objField.appendChild objFieldValue
 
  End If
 Next
 
 'Create the xml processing instr.
 Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
 
 'Append processing instruction to the XML document.
 objDom.insertBefore objPI, objDom.childNodes(0)
 
 'Save the XML document.
 objDom.save strXMLFilePath & "\" & strFileName
 
 'Release all of your object references.
 Set objDom = Nothing
 Set objRoot = Nothing
 Set objField = Nothing
 Set objFieldValue = Nothing
 Set objattID = Nothing
 Set objPI = Nothing
End Function
 
'no break on error.
On Error Resume Next
 
'save the file.
ConvertFormtoXML "E:\drive\drivelocation", "NAMEIWANTDYNAMIC.xml"
 
 
'Test to see if an error occurred.
If err.number <> 0 then
 Response.write("An error has occurred while saving your form submission.")
Else
 Response.write("Your input has been saved.")
End If
%>
 
  1.  
  2. Line number On/OffCode: Select all
  3. <%
  4.  
  5. Function ConvertFormtoXML(strXMLFilePath, strFileName)
  6.  
  7.  Dim objDom
  8.  Dim objRoot
  9.  Dim objField
  10.  Dim objFieldValue
  11.  Dim objattID
  12.  Dim objPI
  13.  Dim x
  14.  
  15.  Set objDom = server.CreateObject("Microsoft.XMLDOM")
  16.  objDom.preserveWhiteSpace = True
  17.  
  18.  Set objRoot = objDom.createElement("debrief")
  19.  objDom.appendChild objRoot
  20.  
  21.  For x = 1 To Request.Form.Count
  22.  
  23.   If instr(1,Request.Form.Key(x),"btn") = 0 Then
  24.  
  25.    'Create element "field".
  26.    Set objField = objDom.createElement("field")
  27.  
  28.    'Create attribute "id".
  29.    Set objattID = objDom.createAttribute("id")
  30.  
  31.    'Set the value of attribute
  32.    objattID.Text = Request.Form.Key(x)
  33.  
  34.    'append the id attribute to field element.
  35.    objField.setAttributeNode objattID
  36.  
  37.    'Create a new element, "field_value".
  38.    Set objFieldValue = objDom.createElement("field_value")
  39.  
  40.    'value of field_value element equal to value of current field.
  41.    objFieldValue.Text = Request.Form(x)
  42.  
  43.    'Append field element as child of root.
  44.    objRoot.appendChild objField
  45.  
  46.    'Append field_value element as child of field elemnt.
  47.    objField.appendChild objFieldValue
  48.  
  49.   End If
  50.  Next
  51.  
  52.  'Create the xml processing instr.
  53.  Set objPI = objDom.createProcessingInstruction("xml", "version='1.0'")
  54.  
  55.  'Append processing instruction to the XML document.
  56.  objDom.insertBefore objPI, objDom.childNodes(0)
  57.  
  58.  'Save the XML document.
  59.  objDom.save strXMLFilePath & "\" & strFileName
  60.  
  61.  'Release all of your object references.
  62.  Set objDom = Nothing
  63.  Set objRoot = Nothing
  64.  Set objField = Nothing
  65.  Set objFieldValue = Nothing
  66.  Set objattID = Nothing
  67.  Set objPI = Nothing
  68. End Function
  69.  
  70. 'no break on error.
  71. On Error Resume Next
  72.  
  73. 'save the file.
  74. ConvertFormtoXML "E:\drive\drivelocation", "NAMEIWANTDYNAMIC.xml"
  75.  
  76.  
  77. 'Test to see if an error occurred.
  78. If err.number <> 0 then
  79.  Response.write("An error has occurred while saving your form submission.")
  80. Else
  81.  Response.write("Your input has been saved.")
  82. End If
  83. %>
  84.  



any and all help very much appreaciated.

thanks,
dogbert.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 49 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.