如何创建一个基于ID的PHP表单? [英] How to create an ID based PHP form?
问题描述
我想基本上创建一个PHP表单,根据您输入的内容将数据存储到数据库中,这当然是基本的.
I want to basically create a PHP form that stores data into a database - based on what you enter - this is of course basic.
但是,有一个怪癖:
此php表单必须基于ID-提供链接.
This php form must be id based - given a link.
让我们说像mywebsite.com/form.php=id446
之类的东西会生成与mywebsite.com/form.php=id447
之类的东西截然不同的形式.
Let's say something like mywebsite.com/form.php=id446
will generate a much different form than something like mywebsite.com/form.php=id447
.
两种形式的区别在于大约3-4个形式字段(无论它们是否出现),其余都是相同的
The difference in both the forms is about 3-4 form fields(whether they appear or not), rest is the same
现在,我可以蛮力地制作form446.php
,form447.php
等-但我宁愿不这样做.
Now, I could brute force this and just make form446.php
, form447.php
, etc. - but I'd rather not.
那么有没有允许我执行此操作的功能?
So is there any function that allows me to do this?
还有,是否有任何模板可用于制作美观且令人赏心悦目的php表单-使它们更易于填充?
Also, is there any template for making aesthetic and eye-pleasing php forms - that make them easier to fill?
谢谢大家, xoxo
thanks guys, xoxo
推荐答案
您可以使用单个form.php,但是要使用代码中的if结构来包括/排除各个部分-就像这样:
You can use a single form.php but use if structures in the code to include / exclude the individual parts - so something like:
<form action="doForm" method="post">
Input 1: <input type="text" id="input1"/>
Input 2: <input type="text" id="input1"/>
<?php
//This field only appears if you hit the url form.php?formid=123
if($_GET['formid'] == 123):
echo 'Input 3: <input type="text" id="input3"/>';
endif;
?>
<input type="submit" id="submit" value="submit" />
</form>
作为服务器端脚本语言,PHP并不是制作漂亮,可用的表单所需要的-它只关心它们的功能处理.对于漂亮的表格,您可能需要一些漂亮的HTML/CSS和javascript.有一个用于可用表单"的Google,并查看以下jQuery插件列表以获取想法:
Being a server-side scripting language, PHP isn't what you need for making pretty, usable forms - it only cares about the functional processing of them. For pretty forms, you'll probably want some nice HTML / CSS and javascript instead. Have a google for "usable forms" and check out things like this list of jQuery plugins for ideas: http://www.queness.com/post/204/25-jquery-plugins-that-enhance-and-beautify-html-form-elements
-编辑- 我是否应该假设您还需要大约10000种具有自己独特元素的不同形式?我希望不是这样(出于您自己的理智!).如果您完全可以减少这种情况,那么您可能想尝试将formType作为URL参数而不是仅作为ID添加,这样您就可以将这些解析成组了.
--- Edit ---- Should I assume you also need about 10000 different forms with their own unique elements? I hope (for your own sanity!) that's not the case. If you can reduce that at all then you might want to try adding formType as a url parameter instead of just the ID, that way you can parse those out in groups instead.
说实话,这是我无论如何都要使用数据库的工作-我将建立一个表来保存每个表单的ID号以及与其关联的元数据的另一个字段(可能是数组,甚至是序列化的大批).然后,您可以将其提取到应用程序中,并且仍然可以使用formId作为唯一的url参数.从您的其他评论中,我猜认为保存已保存数据的表不是特定于formId的,因此这可能应该可以工作.
To be honest this is the sort of job I'd use a database for anyway - I'd set up a table to hold each form's ID number and another field for its associated metadata (maybe in an array or even a serialised array). You could then extract that out in the application and you can still go by using the formId as the only url parameter. From your other comments I guess that the table that holds the saved data isn't formId specific, so this should probably work.
这篇关于如何创建一个基于ID的PHP表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!