Repository navigation
Give a button with no name a name of its own - #438
Merged
Merged
Conversation
This was referenced Sep 23, 2026
A submit, reset or JS button, or an image input, without a name read the missing fieldname and warned. The print_ob_* methods now guard that read as they guard the attributes beside it, and an unnamed button is named after its kind and field number (Submit_1, Reset_2, Button_3) so two of them stay two fields with their own actions. Other unnamed fields are refused with mPDF's own exception instead of a warning first. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…overlapping tests Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
jakejackson1
force-pushed
the
fix/147-unnamed-button-fieldname
branch
from
September 23, 2026 19:38
cb3bc91 to
c28e0b1
Compare
This was referenced Sep 23, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #147
HTML does not require a button to have a name: a submit button without one triggers the form but is not sent with it. With
useActiveFormson, mPDF warned on these buttons (and PHP 5–7 raised a notice), because theForm::print_ob_*methods read$objattr['fieldname']without checking it was set.Tag\Inputonly sets that key when the element has aname.What changed
The name read is guarded. The
print_ob_*methods now readfieldnamewith the sameisset()guard as the optional attributes beside it, falling back to''. The hidden-input call inTag\Inputgets the same guard. A text, hidden, textarea, select, checkbox or radio field with no name is still refused, but now only by mPDF's ownMpdfException("must have a name attribute"), with no warning before it.Unnamed buttons get distinct names.
SetFormSubmit(),SetFormReset()andSetJSButton()now name an unnamed buttonSubmit_<n>,Reset_<n>orButton_<n>, where<n>is the field's number. Image inputs go throughSetJSButton(). A fixed name would merge buttons:Submitand an unnamed reset toReset, so two of either were written as two fields with the same/T. Viewers treat same-named fields as one field.array_form_button_js) and image icon (form_button_icon) are looked up by name. A second button under the same name would replace the first button's action or icon.nullname fails the name check. It now renders.The number is
formCount + 1, which is thenthatSetFormButton()gives the field.formCountis part ofForm's state snapshot, so a button measured forpage-break-inside: avoidand then drawn again keeps the same name. I checked this by hand.Named buttons are unchanged. The only visible difference is the
/Tof a button that had no name:SubmitbecomesSubmit_1. Unnamed buttons are not submitted, so nothing depended on that value.Snapshots
None changed. No snapshot has an unnamed button.
Verification
tests/Mpdf/UnnamedButtonTest.php:MpdfExceptionand does not warn.composer test: 3608 tests, 16039 assertions, OK (5 skipped, as ongravitypdf)composer test -- --group=snapshot: 85 tests, OKcomposer cs: cleanphp -lunder PHP 5.6 on every changed fileUpstream
The same code is in mpdf/mpdf, and the diff applies there as it stands.
🤖 Generated with Claude Code