how to handle forms in multiple pages?

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.

Leave a Comment