Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

bcworkz on "handling form data"

$
0
0

The issue here is if your form processing script needs to use any WP functions, you need to have your script initialize the WP environment. The ways this can be done is quite limited. You can use AJAX, or run requests through admin-post.php. Your only other option is to create a custom page template, then create a page using it. Your form action can then be the page's permalink.

The page template option has issues for plugins. Templates are supposed to be in the current theme's folder. You used to be able to leave them in a plugin folder and change the template reference in post meta. That doesn't seem to work any more. There's some code floating about that fools WP into thinking plugin templates are in the theme folder though they are with the plugin. I can find a link if you're really interested in this route.

AJAX is pretty well documented, but be aware there is a WP way of doing AJAX that differs from what you usually see. The request has to go through admin-ajax.php. Your PHP script ends up being a callback to a do_action() call from that file.

The admin-post.php is really the simplest, but there is little documentation. It's simple enough you can probably figure it out. It's sort of like AJAX, but you don't need javascript or jQuery. Regular POST or GET requests work. If just examining the file isn't enough, try this article. It initially goes off on a misleading tangent, so don't stop reading and try the first example with wp-load.php. It turns out to be a bad idea.


Viewing all articles
Browse latest Browse all 26892

Trending Articles