0

In a theme I have a form that I need posted and some work done on the server. What is the recommended way of doing this?

I have it posting to another php file where some work will be done, and then redirected back to the previous url. I'm having some issues with this because all the functions that normally work in a page don't anymore; such as home_url() and get_current_user_id(). Is there a good/easy way to include the basic WP things to use?

Does the php file need to be a wordpress page? Is this even a good way doing this?

2
  • Is this for wp-admin or the front-end? Jul 21, 2012 at 6:20
  • For the front end.
    – Josh Close
    Jul 21, 2012 at 6:32

1 Answer 1

1

I recommend you take a look at the AJAX in Plugins page which should solve your woes with redirects. http://codex.wordpress.org/AJAX_in_Plugins

You can send whatever you want to be processed asynchronously. This is a pretty standard way of processing forms in WordPress both on the front-end and back-end.

If you need to include user data, add the current user ID to the jQuery.post data array to be sent to your AJAX hook.

2
  • I'd much rather do Ajax anyways. I wanted to whip up something quickly and found that things don't work the same on non templated files.
    – Josh Close
    Jul 21, 2012 at 6:35
  • Yep. This keeps everything in the WP load sequence. Jul 21, 2012 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.