In fapi3, it is very easy to have buttons on a page have an arbitrary submit path. This is an incredibly valuable feature, and opens the API up to easily adding buttons that do tasks that are not necessarily form submission.

However, the validate path still assumes form submission. For example, if an item has '#required' => 'TRUE' on it, *any* button clicked will cause this requirement to be checked, and the button's submit handler NOT called if that field has no value.

Unfortunately, if I have a 'Cancel' button on the form, whose task is to cancel the form, undo changes, and in general do very button-like behavior but does not save values in the form, you still must add a value before you can cancel. This is bad UI, and I"ve discovered that I cannot use #required => TRUE on forms where I have a Cancel button. (In Views, this turns out to be almost all forms).

Likewise, I have other buttons that change the Override or Exposed filter status; they need to be buttons since they actually change the nature of the form, almost as though being multi-step.

These buttons need to have a setting that allows them to absolutely skip validation. Heck, for all I care they could skip processing too; the form values are immaterial if I Cancel the form, so why waste the processor time setting up the values?

I'm not completely sure this qualifies as a bug report, but it seems like a bug because I am basically unable to use #required => TRUE and have to use extra validation code to use a feature which already exists. It's got an easy workaround, of course, which is "Don't use #required". I am concerned, though, that this means I couldn't have a node form that has extra buttons on it that do things.

(Also, node forms have a delete button; it seems wrong that Delete should fail if there is invalid data in the form. Who cares?)

Comments

AltaVida’s picture

Yes, this is a big problem. As mentioned, clicking the delete button on a node edit page triggers validation (see http://drupal.org/node/216064 ). This also appears to be the case for deleting a user ( see http://drupal.org/node/274547 ).

This seems to be a pretty major FAPI bug.

Possible solution: Allow a button element to have '#validation' => FALSE to skip all form validation.

Anonymous’s picture

Yea, this is a definite DX issue. I created a hack for Cancel that is documented here http://drupal.org/node/303107#comment-1255728 and here #337264-13: Cancel Button does not work. I'd prefer the entire validation be skipped as AltaVida suggests.

coltrane’s picture

cdale’s picture

I've pulled together a module which allows the skipping of the validation procedures by clicked button for D6.

http://drupal.org/project/skip_validation

casey’s picture

Status: Fixed » Closed (fixed)
Issue tags: -DX (Developer Experience)

Automatically closed -- issue fixed for 2 weeks with no activity.