简体   繁体   English

如何在WordPress中捕获表格textarea值并将其插入mysql?

[英]How can I capture a form textarea value in WordPress and insert into mysql?

I see all sorts of people asking this but no solid answers. 我看到各种各样的人都在问这个问题,但没有明确的答案。 I want to take text from a textarea form where users can enter their bio and then insert it into the bio field in mysql. 我想从textarea表单中获取文本,用户可以在其中输入自己的履历,然后将其插入mysql的bio字段中。 This might be fairly easy normally, but alas, it seems nearly impossible with WordPress. 通常,这可能相当容易,但是可惜的是,使用WordPress似乎几乎是不可能的。 I have to use the "Php for posts and pages" plugin and for some reason, the php script I have cannot be found (404 error) no matter where I place it. 我必须使用“用于帖子和页面的Php”插件,由于某种原因,无论放置在哪里,都无法找到我的php脚本(404错误)。 Then I thought I would try to just make the form and php all on one WordPress page, but it apparently can't be done like on a normal php web page. 然后我想我会尝试只在一个WordPress页面上制作表单和php,但是显然不能像在普通的php网页上那样完成。 Anyone have any experience doing this? 任何人都有这样做的经验吗? Any approaches that are known to work? 有已知有效的方法吗?

You can make form using normal php and insert it into mysql. 您可以使用普通的php制作表格并将其插入mysql。 You can do this by making page template in wordpress. 您可以通过在wordpress中制作页面模板来做到这一点。

http://codex.wordpress.org/Page_Templates http://codex.wordpress.org/Page_Templates

I've went through the same process! 我经历了同样的过程! :) :)

My solution was: 我的解决方案是:

Installing a PHP insertor plugin (specifically this ). 安装PHP插入程序插件(特别是this )。 It's lot easier than creating a template. 比创建模板要容易得多。

I used it like this (inserted into the post's source): 我这样使用它(插入帖子的源代码中):

[insert_php] include('myphpfile.php'); [/insert_php]

Then the included PHP's contents will be processed and printed out inside the page's body (the article's main part), so you don't have to create the html, head and body tags. 然后,所包含的PHP内容将被处理并打印页面的正文(文章的主要部分)内,因此您不必创建html,head和body标记。

Then came the problem with posting form data to a page like this. 然后出现了将表单数据发布到这样的页面的问题。 This was because some of my form's fields kinda conflicted with WP's variables. 这是因为我表单的某些字段与WP的变量有点冲突。

Some of the conflicting field names I've noticed: info , name 我注意到了一些冲突的字段名称: infoname

Just have a look at your form' field names and replace them to something else, and everything will be fine! 只需查看表单的字段名称并将其替换为其他名称,一切都会好起来的! :) :)

PS.: It's possible to put the form and the form data "receiver" in the same PHP script. PS .:可以将表单和表单数据“接收器”放在同一PHP脚本中。 I've done so and it worked in this scenario. 我已经这样做了,并且在这种情况下可以正常工作。

PS. PS。 2: Optionally, you can disable the annoying auto-paragraph-insertor wpautop stock WP plugin, as it's affecting the included PHP's output. 2:(可选)您可以禁用烦人的auto-paragraph-insertor wpautop股票WP插件,因为它会影响随附的PHP的输出。 There is a per-post wpautop disabler plugin: Toggle wpautop 每个帖子都有一个wpautop disabler插件: 切换wpautop

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

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