Contact form throws error on submitting

Created on 24 March 2025, 10 days ago

Problem/Motivation

Core contact form throws error when submitting form.

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of core/lib/Drupal/Component/Utility/Html.php).

Steps to reproduce

Drupal core 11.0.x, php 8.3.
Create contact form, subject field disabled.
Sending e-mail gives above error.

If Subject field is enabled, error goes away.

๐Ÿ› Bug report
Status

Active

Version

11.0 ๐Ÿ”ฅ

Component

contact.module

Created by

๐Ÿ‡ญ๐Ÿ‡บHungary wahavi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wahavi
  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10

    The module sends an email and needs a subject

    Can you elaborate on the use case for hiding the subject?

  • ๐Ÿ‡ท๐Ÿ‡บRussia Alezu

    I confirm that hiding the subject causes a fatal error when submitting the form. I don't think we should look for any use cases since this can only be done in the form display settings page. I have encountered this error at least twice and each time I spent a lot of time trying to find the source. We should have some workaround, like additional validation or a default value for the subject.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia AditiVB

    i am not getting any error even if subject filed is disabled. Do let me know how you are sending email ?

  • ๐Ÿ‡ท๐Ÿ‡บRussia Alezu

    I encounter the error only for anonymous user, debug_backtrace() returns the source of the error like something like "t('@name anonymous', ['@name' => NULL])". As for the current case I do not see any additional mail modules installed and think that finally it is sent by ordinary mail() function.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary wahavi

    Thank you very much for your answers.
    I think users who send messages through a contact form hate filling useless fields, like the subject field. At least this is my own experience. That is why I always disable subject field (and I always did it), and it was not a problem until upgrading to drupal 11. It was my fault that I did not check the contact form then, so there could have been some clients who faced with the error page since then.
    I did not change anything other than uploading the new core and vendor directories. I use the default core email sending mechanism, no other modules (like SMTP or mime mail or such).

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies โ†’ . Restored the issue template. The issue template is used to track progress and various tasks on an issue.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Ishani Patel

    ishani patel โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Ishani Patel

    Hello @wahavi
    I've followed the above issue steps as you mentioned and got the same error when I disable a subject field.
    I resolved that issue and raised an MR
    Please check and review.

    Thanks

  • Pipeline finished with Failed
    6 days ago
    Total: 544s
    #459432
  • Pipeline finished with Failed
    6 days ago
    Total: 819s
    #459446
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sdhruvi5142

    Hi
    I've applied MR!11668 and verified on Drupal version on 11.0.x and it is working as expected.

    Testing Steps:
    1. Installed Contact Module
    2. Created a webform and disabled Subject field
    3. And oberved the change there.

    Testing Result:
    After applying the MR the, when user disable the subject field, the form is getting submitted succesfully without error. Attaching SS for reference. As MR have some error so keeping in Needs review status.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Should have a test case showing the issue.

    Also issue summary is incomplete.

  • ๐Ÿ‡ท๐Ÿ‡บRussia Alezu

    I am not sure we should deal with this problem in FormattableMarkup but as soon as converting to string already present there let it be... Please review my addition to the tests.

Production build 0.71.5 2024