在wordpress中提交Web表单
问题描述:
I\'m pretty newbie in wordpress and I\'m having some difficulties dealing with a simple form layout / submission.
I have a page (created from the wp-admin page) that holds the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<div class=\"container-fluid\"> <form class=\"form-horizontal\" action=\"\" method=\"POST\" > <div class=\"row form-group\"> <div class=\"col-xs-12\"> <label for=\"name\">Nome</label> <input type=\"text\" class=\"form-control\" id=\"name\" name=\"name\" /> </div> </div> <div class=\"row form-group\"> <div class=\"col-xs-12\"> <label for=\"residence\">Residência</label> <input type=\"text\" name=\"residence\" id=\"residence\" /> </div> </div> <div class=\"row form-group\"> <div class=\"col-sm-6\"> <input class=\"btn btn-default\" type=\"submit\" value=\"Registar\"> </div> </div> <form> </div> |
My problem here is that I don\'t know what to put in the action attribute and how to process the form afterwards. I have tried to create a php file in the template folder and put it in the action but it did not work at all.
I have also seen some actions that can be added to functions.php but I don\'t see that as the best solution to the problem. All I want is to submit the form, store it in the database as meta-data and redirect the user to the main page.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议
我是wordpress中的新手,我在处理简单的表单布局/提交方面遇到了一些困难。 我有一个页面(从wp-admin页面创建),其中包含以下代码:</ p>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
&lt; div class =“container-fluid”&gt; &lt; form class =“form-horizontal”action =“”method =“POST”&gt; &lt; div class =“row form-group”&gt; &lt; div class =“col-xs-12”&gt; \\ n&lt; label for =“name”&gt; Nome&lt; / label&gt; &lt; input type =“text”class =“form-control”id =“name”name =“name”/&gt; &lt; / div&gt; &lt; / div&gt; &lt; div class =“row form-group”&gt; &lt; div class =“col-xs-12”&gt; &lt; label for =“residence “&gt;Residência&lt; / label&gt; &lt; input type =”text“name =”residence“id =”residence“/&gt; &lt; / div&gt; &lt; / div&gt; &lt; div class =“row form-group”&gt; &lt; div class = “col-sm-6”&gt; &lt; input class =“btn btn-default”type =“submit”value =“Registar”&gt; &lt; / div&gt; &lt; / div&gt; &lt; form&gt; &lt; / div&gt; </ code> </ pre> <p>我的问题是我不知道要在action属性中添加什么以及如何处理表单 然后。 我试图在模板文件夹中创建一个php文件并将其放入操作中,但它根本不起作用。 我也看到了一些可以添加到functions.php的动作,但我不认为这是解决问题的最佳方法。 我想要的只是提交表单,将其作为元数据存储在数据库中,并将用户重定向到主页面。</ p> </ div> <h5>网友观点:</h5> <div> <p>My suggestion is to use <code>action=\\\"#\\\"</code>, which redirects the user to the current page on pressing submit. You can then have a check for a hidden field that does not display the form and instead checks the data and stores it in the database, then redirects the user to your main page. </p> <p>You can put this file anywhere in the Wordpress installation (So long as your users can access it). If portability is not an issue stick it in the root, or look up <a>making a page template file</a> if portability does matter. </p> <p>Also, careful using the attribute <code>name=\\\"name\\\"</code> as this mucks up your Wordpress page handling I seem to remember (Wordpress uses it to identify what page it is on). </p> <p>Here\'s an example of the same page handling:</p> <pre><code><?php if (isset($_POST[\\\"formSubmitted\\\"])) { $name = $_POST[\\\"formName\\\"]; $residence = $_POST[\\\"formResidence\\\"]; // do database work here with $name and $residence // then output javascript to redirect to main page echo \'<script>window.location = \\\"http://example.com\\\";</script>\'; } else { // we display the form ?> <div class=\\\"container-fluid\\\"> <form class=\\\"form-horizontal\\\" action=\\\"#\\\" method=\\\"POST\\\" > <div class=\\\"row form-group\\\"> <div class=\\\"col-xs-12\\\"> <label for=\\\"name\\\">Nome</label> <input type=\\\"text\\\" class=\\\"form-control\\\" id=\\\"name\\\" name=\\\"formName\\\" /> </div> </div> <div class=\\\"row form-group\\\"> <div class=\\\"col-xs-12\\\"> <label for=\\\"residence\\\">Residência</label> <input type=\\\"text\\\" name=\\\"formResidence\\\" id=\\\"residence\\\" /> </div> </div> <div class=\\\"row form-group\\\"> <div class=\\\"col-sm-6\\\"> <input class=\\\"btn btn-default\\\" type=\\\"submit\\\" value=\\\"Registar\\\"> </div> </div> <input type=\\\"hidden\\\" name=\\\"formSubmitted\\\" value=\\\"1\\\"> </form> </div> <?php } ?> |
Alternate solutions could be to use get_stylesheet_directory_uri() which returns the directory where the theme stylesheet is located. You could use this like so:
1 2 |
<form action=\\\"<?php echo get_stylesheet_directory_uri().\\\"/some_php_file.php\\\"; ?>\\\" method=\\\"POST\\\"> |
This would then pass the data to that file, from which you could add it to the database.
###
If you are a beginner, why not just use contact form 7 or gravity forms?
Contact Form 7: http://contactform7.com/
Gravity Forms: http://www.gravityforms.com/
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 在wordpress中提交Web表单