WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 want to provide 2 buttons in one form. User click either button can submit the form but do different jobs-- one button is to import checked files, another button is to create fiels. Will this confuse Wordpress?

share|improve this question

closed as off topic by Brian Fegter, Rarst Oct 2 '12 at 21:30

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Just re-read your question. I had close voted this, but I think it's legit. – Brian Fegter Aug 24 '12 at 5:03
Please rework your question. Currently it's "confuse? Why? No! It's machine & code!". :) – kaiser Sep 25 '12 at 0:57
up vote 1 down vote accepted

If you're placing a button in a meta box, it is included within the FORM tags for a post. A simple answer is no, you shouldn't place a submit button in the post form. However, nstead of using a normal input[type=submit], use the following:

<button type='button' name='button-name' id='button-id'>Button Text</button>'

A click won't process as a submit action, it will just click. You obviously will need to bind the click event to however you're importing your file list. If you're not using AJAX, you should. Check out this article on how to use AJAX in WordPress.

Having a submit button within the form will post to post.php and certainly will have unwanted effects, namely losing any changed data within the post form.

share|improve this answer
It's not metabox in post-form. It's a custom form with workdpress submit_button() – Jenny Aug 24 '12 at 5:22
You can have two separate submit buttons. You will just need to sniff the button names in the $_POST data as the submit button will register a key in the $_POST array. – Brian Fegter Aug 24 '12 at 5:24
How to "sniff" the button names into $_Post data? When the form submitted, I will evalueate..."if(isset($_POST['bla'])", is that enough? Or I have to evaluate which button submitted the form? – Jenny Aug 24 '12 at 5:27
Yes. That should work fine. – Brian Fegter Aug 24 '12 at 5:30
Thanks for helping! – Jenny Aug 24 '12 at 5:34

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