Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Is this for wp-admin or the front-end? –  Brian Fegter Jul 21 '12 at 6:20
    
For the front end. –  Josh Close Jul 21 '12 at 6:32

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '12 at 6:35
    
Yep. This keeps everything in the WP load sequence. –  Brian Fegter Jul 21 '12 at 6:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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