0

Hi how would i GET information from a form that a user enters into a textbox combobox or w.e and write it to a xml file.

either HTML javascript or php will be appreciated.

suffix
  • 99
  • 2
  • 7
  • did you try this in any process? – Ariful Islam Nov 13 '11 at 03:36
  • You can use the method described in best answer here - http://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml. Your `$_POST` will become the `$test_array` used in the example. You can modify it a bit to suit your needs. – Vikk Nov 13 '11 at 03:44
  • @Vikk In this case it isn't really good because the data should be encoded first. – Aurelio De Rosa Nov 13 '11 at 03:46
  • @Aurelio De Rosa Can you explain a bit more? I guess I'm missing something. – Vikk Nov 13 '11 at 03:52
  • @Vikk The data sent by the users can contains chars like '<' or '>' and if you put this chars in a xml file without encoding them (in < and >) this will break the xml file. – Aurelio De Rosa Nov 13 '11 at 03:54

2 Answers2

1

Well, saying that you have a page with a form like:

<form name="form" action="getdata.php" method="post">
   <input type="text" name="tb" />
   <input type="submit" value="Submit" />
</form>

your getdata.php (this is just an example of the name) page, which will collect the data and save them in a xml file, should be like this:

<?php
   $text = htmlentities($_POST['tb']);

   $doc = new DOMDocument();
   $textareaNode = $doc->createElement("textbox");
   $textNode = $doc->createTextNode($text);
   $textareaNode->appendChild($textNode);
   $doc->appendChild($textareaNode);
   $doc->save("data.xml");
?>
Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
0

Here are some links that can get you started.

abhinav
  • 3,199
  • 2
  • 21
  • 25