简体   繁体   中英

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. This might be fairly easy normally, but alas, it seems nearly impossible with 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. 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. 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. You can do this by making page template in wordpress.

http://codex.wordpress.org/Page_Templates

I've went through the same process! :)

My solution was:

Installing a PHP insertor plugin (specifically 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.

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.

Some of the conflicting field names I've noticed: info , name

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. I've done so and it worked in this scenario.

PS. 2: Optionally, you can disable the annoying auto-paragraph-insertor wpautop stock WP plugin, as it's affecting the included PHP's output. There is a per-post wpautop disabler plugin: Toggle wpautop

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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