WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page template having a form which further have 3 input fields and and a submit button. I have a written a function in a plugin which inserts the retrieved values in database. I am trying to figure out what to write in action attribute of the form, so that when user clicks the submit button, the function gets executed?

share|improve this question
Please file an edit and add all the relevant code and info that you have. Without code it is hard to help you – Pieter Goosen Jun 14 '14 at 12:06
up vote 3 down vote accepted

Output The Form

Can be done via Shortcode API.

What Should Be Set on Form Action

Leave it blank <form action="">. Make sure you avoid using reserved name as form field name like name or p. Otherwise your form submission will hit 404.

How Can We Validate or Process The Form?

Hook into template_redirect.

add_action( 'template_redirect', 'wpse149613_form_process' );

function wpse149613_form_process(){
    if(!isset($_POST['submit'])) // assuming you're using POST and submit button name is 'submit'

    // Validate the form, verify nonce

    // process form


Hope it makes sense. This is how I usually handle form submission.

share|improve this answer
It has cleared lot of doubts. Will try to implement the same and mark this question closed once done. :) – imvarunkmr Jun 14 '14 at 12:01

Your Answer


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.