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.

I have a simple contact form that I set up to display on multiple pages using a shortcode and a widget but since I need to form to post back on the same were it's displayed I'm not sure how to accomplish this.

I was thinking about writing a function and plug it to the wp_head hook but I'm not sure if it's correct, is there a better way to do this?

Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Kind of - I would suggest using init. This would probably be the best way of doing it since you can process the form as described below. wp_head would work though. Also, you should make sure you are making necessary checks with 'nonces'.

I suggest the init hook as you can employ something similar to 'post-redirect-get' (see here). This can help against resubmission of data when users click refresh. The usual way of doing this is to submit the url of the page along with the form, submit to a processing page, which when it's finished then redirects the user back to the original page (or a confirmation page).

Of course you don't need a separate 'processing page'. An action hooked onto init can check a form is submitted, check the nonces, process the form and then redirect back to the page.

share|improve this answer
    
That sounds good, I was wondering how to handle form resubmission too, using init would be better since headers haven't already been sent at this point right? –  javiervd Jan 15 '12 at 20:34
    
Yup, you wouldn't able to do that with wp_head –  Stephen Harris Jan 15 '12 at 20:41

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.