Problem/Motivation

The example on the API documentation for form API does not work as a new developer might expect, in that submitForm() is never actually called, given the form API array defined in buildForm(). The form is just reloaded as if it were a GET rather than a POST request.

As far as I can tell, this seems to be because the form builder ignores form submissions if there is no element with '#type' => 'submit' in the form API array. The button doesn't need to be clicked as such; it just needs to be present. When I add a second element to the buildForm() return value, then submitForm() is called fine.

Note that examples.module includes a submit element, so that example works fine.

Proposed resolution

Whether or not the current behaviour of Form API is correct, is not within the scope of this issue.

Instead, this issue only covers changing the documentation must be changed so that the example is the simplest that works, and is also not so simple that it wouldn't be a typical use case (it's rare to find forms without submit buttons nowadays, and such forms might have UX and accessibility issues anyway.)

(Edited after discussion in comments.)

Remaining tasks

1. Work out whether the behaviour I've seen is repeatable.
2. If so, work out how custom form handlers/the form builder ought to work, and then decide whether documentation or code needs fixing.
3. Provide a patch to the documentation.
4. Approve the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#4 custom_form_handler_s-2797721-4.patch515 bytesjp.stacey

Comments

jp.stacey created an issue. See original summary.

joachim’s picture

Component: forms system » documentation

I'd say this is a documentation bug.

Even if having a form with no submit button were possible with FormAPI, we would not want to show that in example code -- it's really bad UX.

jp.stacey’s picture

Issue summary: View changes

@joachim I agree with that assessment: even if the behaviour is up for discussion, it could be a long discussion; far better for codebase and documentation to be in sync in the mean time. Editing ticket description to match.

jp.stacey’s picture

Status: Active » Needs review
StatusFileSize
new515 bytes

Patch attached for review.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +rc eligible

Committed and pushed 85a227f to 8.3.x and 36ee1e0 to 8.2.x. Thanks!

Docs patches are RC eligible.

  • alexpott committed 85a227f on 8.3.x
    Issue #2797721 by jp.stacey: Custom form handler's submitForm not called...

  • alexpott committed 36ee1e0 on 8.2.x
    Issue #2797721 by jp.stacey: Custom form handler's submitForm not called...

Status: Fixed » Closed (fixed)

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