Wordpress - 我应该将 html 表单存储在模板中还是页面内容中?
我想知道在 WordPress 中存储 html 表单的最佳实践是什么。我可以将表单的代码存储在模板文件中,也可以将其存储在页面内容中。
我不知道最终管理员用户的技术能力,所以我可以将其存储在模板中,他无法编辑和破坏它。或者我可以将其存储在页面内容中,他可以在其中编辑和销毁表单。
*请注意,此表单样式繁重,需要支持 javascript。
I am wondering what is the best practice when it comes to storing html forms in Wordpress. I can either store the code for the form in a template file or I could store it in the page content.
I do not know the technical ability of the end admin user, so I can store it in a template where he cannot edit and break it. Or I can store it in the page content where he can edit and destroy the form.
*Note this form is heavy styled and requires supporting javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有真正回答这个问题 - 但是当在 WordPress 中使用表单时,我会认真考虑使用联系表单 7 插件 - 它完全可定制,并且可以在 WordPress 网站上的任何位置拥有多个表单
Not really answering the question - but when using forms in wordpress I would seriously consider using contact forms 7 plugin - its completely customisable and can have multiple forms anywhere on your wordpress site
@罗布是对的;但他没有回答你的问题。
如果您因任何原因必须自定义此表单,则必须考虑以下事项:
技术水平较低的人是否能够访问您的表单?
如果有人使用可视化编辑器来编辑表单,您可能会遇到很多问题。如果这是一个问题,我建议将其存储在模板中。
使用简码:
如果必须以表格形式存储;您可能想将其转换为短代码并将其添加到主题的functions.php 文件中。这将是最佳实践。
如果您对此不熟悉,请查看简码 API:http://codex.wordpress.org/Shortcode_API
@rob is right; but he's not answering you question.
If you must do this form custom for any reason you must consider the following:
Is someone of less technical savviness going to be able to access your forms?
You may run into lots of problems if someone uses the visual editor to edit the forms. I would recommend storing it in the template if that is an issue.
Use a shortcode:
If you must store it in a form; you may want to convert it into a shortcode and add it into your functions.php file for your theme. This would be best practice.
Review the shortcode API if you're not familiar with this: http://codex.wordpress.org/Shortcode_API
为了让后端用户轻松使用,最好的方法可能是创建一个新的短代码。
让我们称之为[showform]
只需转到您的functions.php 并执行以下操作:
您还可以使用联系表单7 插件来实现普通表单或以HTML 模式粘贴代码
我还使用了execPHP 插件来在内容中包含文件。您可以将 form.php 存储在主题文件夹中,然后在 HTML 编辑器中使用:
希望有帮助
Probably the best way in order to make it easy for your backend user is create a new shortcode.
Lets call it [showform]
Just go to your functions.php and do:
You can also use contact form 7 plugin for normal forms or paste the code in HTML mode
I also used execPHP plugin to include files on the content. You can store the form.php in your theme forlder and then in the HTML editor use:
Hope it helps