Skip to content

A submit, reset or JS button with no name warns: Form.php reads objattr["fieldname"] unguarded #147

Description

@jakejackson1

Form::print_ob_button() reads
$objattr['fieldname'] without checking it is there:

} elseif ($objattr['subtype'] === 'SUBMIT') {
	$url = $this->formAction;
	$type = $this->formExportType;
	$method = $this->formMethod;
	$this->SetFormButtonText($objattr['value']);
	$this->SetFormSubmit($w, $h, $objattr['fieldname'], ...);

Form.php:532, with the same read at :526 (RESET) and :540 (BUTTON). The neighbouring
optional attributes on the same lines - background-col, border-col, noprint - are all
isset()-guarded, so the shape is deliberate everywhere except this one.

Tag\Input only sets fieldname when the element carries a name, and the HTML spec does
not require one on a submit button: a submit button with no name is not submitted, which is
the ordinary way to write a button that only triggers the form.

Reproducing

$mpdf = new Mpdf();
$mpdf->useActiveForms = true;
$mpdf->WriteHTML('<form><input type="submit" value="Go"></form>');
$mpdf->Output('', 'S');
Warning: Undefined array key "fieldname" in src/Form.php on line 532

Adding name="go" silences it.

Expected: a submit button with no name is given whatever SetFormSubmit() uses for an unnamed
field, the way the optional colours beside it are handled. Observed: a warning under PHP 8, a
notice under PHP 7, and null passed as the field name.

Found while fixing #141; not that issue's shape and deliberately left out of that PR.

Measured on 2982df6, PHP 8.5.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions