I have posted an example page with a form to show discrepancies in the way the documentation describes the Forms API button elements and #submit attribute and the way it's actually making and processing the forms.

The URL with this issue description and example form is:
http://www.ubercart.org/forms_api_buttons_and_submits/194

Issue:
On a clean install of 5.0, notice that the button is still created as a submit. Also, with a required field, notice that submit 2 which has #submit = FALSE still tries to validate and submit the form. Ideas for change:

1) Update the documentation. See the discrepancy for buttons. See the discrepancy for #submit.

2) Actually fix the code to bring it in line with the documentation. I think this is the better idea for a couple reasons...

  • First, I (and others) use cancel buttons on forms. Right now the hack is to use $_POST to check the op in validation and using drupal_goto to stop validation/submission. (See http://drupal.org/node/100675.) If #submit == FALSE I'd like to see the form at least bypass validation so you can check the op in the submit function and kick out instead of processing a form regularly. I realize then that the attribute name for #submit becomes counter-intuitive, so maybe this even needs a change to #validate. Or maybe if #submit == FALSE you can have the option of setting #redirect and have the forms API detect this and drupal_goto() you on your way automatically. Thoughts?
  • Second, it would be very useful to have a plain ol' button type. So I'd love to see #type = 'button' actually make button elements. I'm not sure what led them to be kept as submits, but through development of Übercart I've had to use either jQuery to add a 'return false;' click function to appropriate submits or put it into the form array in #attributes. (Especially for forms I'm using in AJAX populated divs.. cancel and action buttons alike.) Supporting the button would remove that need. (Granted, I could just use jQuery to append the button to the form with $(document).ready()... I can see that as a reason for not having buttons - forcing developers to use graceful degradation. I don't see any reason to force people to do so, though, because individual dev's may not care about graceful degradation on their sites.)

Thanks for reading!

Comments

rszrama’s picture

(Sorry, figures I would find two other forms API issues on the front page... I only did a few advanced searches on the issues queue and turned up nothing for forms API button or forms button. My apology for some duplication, but there are some areas of difference from the others here, too. ; )

chx’s picture

Status: Active » Fixed

buttons got #submit handlers in form api 3. Yay!

rszrama’s picture

The new API looks great. Thanks for reminding me how much good stuff happens around here. It was nice meeting you at the Drupalcon, too. Hope you had a great time, too!

Anonymous’s picture

Status: Fixed » Closed (fixed)