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 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 at 12:06

1 Answer 1

up vote 2 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'
        return;

    // 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 at 12:01

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.