简体   繁体   中英

Use PHP to pass the contents of a form into a new xml file with download prompt

I'm new to programming so any guidance would be great, what I'm trying to achieve is as follows:

  1. Have a simple html form with some fields (text areas and text fields)
  2. When submiting the form open a dialog to choose location to save the file, file name should be default set to the forms first text area.
  3. Save the file and add the contents of the form to specific xml tags

For instace

I want to capture the content of a text area name "articlebody" and have it saved on the file under the tag

Can someone point me to the right tutorials? Or upload a snippet? Thanks for your time.

Going off the top of my head:

form:

<form action="" method="POST">
1. filename: <input type="text" name="filename" /><br />
2. field 1: <input type="text" name="field1" /><br />
3. field 2: <input type="text" name="field2" /><br />
</form>

script:

$filename = $_POST['filename'];
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];

$field1 = htmlspecialchars($field1);
$field2 = htmlspecialchars($field2);
$xml = <<<EOL
<rootnode>
    <field>$field1</field>
    <field>$field2</field>
</rootnode>
EOL;

header('Content-type: text/xml');
header('Content-length: ' . strlen($xml));
header("Content-disposition: attachment;filename=$filename");
echo $xml;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM