Skip to content

Leave an active button with an empty value blank instead of showing its field name (#459) - #489

Merged
jakejackson1 merged 2 commits into
gravitypdffrom
fix/459-blank-empty-button-caption
Sep 28, 2026
Merged

jakejackson1 merged 2 commits into
gravitypdffrom
fix/459-blank-empty-button-caption

Conversation

@jakejackson1

@jakejackson1 jakejackson1 commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

With useActiveForms on, a submit, reset or script button with value="" showed its field name as its caption. The same button drawn without active forms, and in a browser, is blank.

Cause. Form::_putform_bt() wrote the field name as /MK /CA, /RC and /AC whenever the caption was falsy. #387's appearance stream copied that fallback ($value === '' ? $name : $value) so it would match what a viewer draws. Since #438, an unnamed button gets a generated name ("Submit_1"), so an unnamed button with value="" showed that as well. With embedded fonts, /CA was already an empty UTF-16 string (a lone BOM), which is truthy, but the appearance still drew the name.

Fix.

  • The three copies of the caption code are now one method, buttonCaptions(). A caption set through SetFormButtonText() is written as it is, even when empty.
  • The name is used only when no caption was set (null). That covers image buttons, whose icon replaces the caption (/TP 1), and callers who use SetFormSubmit()/SetFormReset()/SetJSButton() directly without SetFormButtonText(). Their output does not change.
  • The appearance follows the same rule, so it still draws what a viewer would draw from /CA.
  • A button with no value attribute is not affected. Tag\Input gives it "Submit", "Reset" or "Button", and both modes draw that.
  • In core-font mode, a button with value="0" used to show its name because "0" is falsy. It now shows "0".

Tests. tests/Mpdf/ButtonCaptionTest.php covers submit, reset and script buttons with an empty value, no value, and a value, plus an unnamed submit with value="":

  • active: /CA, /RC and /AC are the value, and the appearance draws it;
  • static: the page draws the same caption;
  • with an embedded font, the empty caption is an empty string and the appearance draws no text;
  • an image button keeps its name as /CA.

A new snapshot, empty-button-caption (tests/Snapshots/EmptyButtonCaptionSnapshotTest.php), draws active submit, reset and script buttons with value="", no value, value="Send" and value="0", plus an unnamed submit. Before the change, the empty-value buttons show their names squeezed into the button ("sub", "reset", "butt", "Sub"). After it, they are blank.

Without the change in src/Form.php, 9 of the unit tests and the new snapshot fail. The full suite, phpcs and PHPStan pass. No existing snapshot fixture changes.

Base. PR #448 (#408) is on gravitypdf. PR #441 (#433) was merged into feature/pdfa-2-conformance, and that branch came into gravitypdf through #330 as a rewritten commit (16dc47b), so this change is made on top of both.

Upgrade note

In active forms (useActiveForms), a push button (<input type="submit">, type="reset" or type="button") with an empty value now has an empty caption. Previously it showed the field's name, or a generated name such as Submit_1 if it had none. This is what the same button looks like without active forms, and in a browser. To keep a caption, give the button a value, or leave out the value attribute to get the default "Submit", "Reset" or "Button".

Fixes #459

🤖 Generated with Claude Code

@jakejackson1 jakejackson1 added bug Something isn't working create-upstream-pr labels Sep 28, 2026
jakejackson1 and others added 2 commits September 28, 2026 12:45
…ts field name

A submit, reset or script button with value="" wrote its field name as its
/MK /CA caption, and its appearance drew the name as well, while the same
button drawn without active forms, and in a browser, has no caption. The
caption is now written as given, even when empty. A button whose caption was
never set, such as an image button, still falls back to its field name.

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
jakejackson1 force-pushed the fix/459-blank-empty-button-caption branch from 16cc1ba to 484bb38 Compare September 28, 2026 02:47
@jakejackson1
jakejackson1 merged commit 3a011e0 into gravitypdf Sep 28, 2026
32 checks passed
@jakejackson1
jakejackson1 deleted the fix/459-blank-empty-button-caption branch September 28, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working create-upstream-pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leave an active button with an empty value blank instead of showing its field name

1 participant