[英]Best way to load and save HTML form data to an xml file?
I know you can't do this with just HTML, or JavaScript. 我知道您不能仅使用HTML或JavaScript来执行此操作。 I am using PHP, JavaScript, and HTML.
我正在使用PHP,JavaScript和HTML。 What I want to do is have a form that a user can fill out then when submit is pressed all the form data is saved to an xml file.
我想做的是有一个用户可以填写的表单,然后按提交时,所有表单数据都保存到xml文件中。 Then when the web page is brought up again all the data from the xml file is loaded into the form.
然后,当再次打开网页时,来自xml文件的所有数据都将加载到表单中。 I am currently using PHP to save to xml which is working fine.
我目前正在使用PHP保存到xml,它工作正常。 My min problem is how I am loading the xml file, I am using PHP embedded into my HTML which I feel is becoming very convoluted.
我的最小问题是我如何加载xml文件,我正在将PHP嵌入到HTML中,这让我感到非常困惑。 I wanted a way to just load the xml data in one section of my code, rather than scattered about.
我想要一种只在我的代码的一部分中加载xml数据而不是分散的方法。 I was able to do this with saving the form data, but loading seems to be a bit more challenging.
我可以通过保存表单数据来做到这一点,但是加载似乎更具挑战性。
<td><input type="text" name="person_name" value="<?php echo $config->main->calling->general->person_name;?>"></td>
There are a bunch of these kind of statements... 有很多这样的陈述...
There isn't really a way around that per se. 本身并没有真正的解决方法。 That is how PHP is going to work in general.
这就是PHP通常将如何工作的方式。 I mean you can mitigate it by not using the XML structure directly.
我的意思是您可以通过不直接使用XML结构来缓解这种情况。
Like pull out the specific data you need and make separate variables an array or an object and then just output from those. 就像提取特定数据一样,将单独的变量设置为数组或对象,然后从其中输出即可。 Personally I would probably use an object and treat the XML like a datasource.
就个人而言,我可能会使用一个对象并将XML视为数据源。 That way you could do something like:
这样,您可以执行以下操作:
<td><input type="text" name="person_name" value="<?php echo $config->getSomethingSpecific();?>"></td>
Of course depending on how deeply your structure is nested and what not this might not buy you much unless you only use a subset of the XML data. 当然,取决于您的结构嵌套的深度,如果您仅使用XML数据的子集,这可能不会为您带来多少好处。 Even then you are likely just trading object access with
->
for array access with []
"macros" by using method calls. 即使那样,您也可能只是通过使用方法调用将对象访问权限与
->
交换为使用[]
“宏”进行数组访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.