简体   繁体   English

使用PHP将表单内容传递到具有下载提示的新xml文件中

[英]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) 具有一些字段(文本区域和文本字段)的简单html表单
  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 保存文件并将表单内容添加到特定的xml标记中

For instace 为了实例

I want to capture the content of a text area name "articlebody" and have it saved on the file under the tag 我想捕获文本区域名称“ articlebody”的内容,并将其保存在标签下的文件中

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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