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.

1 Answer 1


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.

  • 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? Commented Jan 15, 2012 at 20:34
  • Yup, you wouldn't able to do that with wp_head Commented Jan 15, 2012 at 20:41

Your Answer

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

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