Problem/Motivation

When registering for an event, none of the fields in the RegistrantForm are required. When the form is submitted without entering an email address, a fatal error occurs.

Steps to reproduce

  1. Create an event series.
  2. Enable registration.
  3. Go to one of the event instances and click "Register".
  4. Don't fill in the email address, just scroll down and press "Register" again.

Result:

TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in /var/www/html/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 123 in Drupal\Core\Mail\Plugin\Mail\PhpMail->doMail() (line 168 of core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php).

Drupal\Core\Mail\Plugin\Mail\PhpMail->mail() (Line: 308)
Drupal\Core\Mail\MailManager->doMail() (Line: 181)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 180)
Drupal\Core\Mail\MailManager->mail() (Line: 426)
recurring_events_registration_send_notification() (Line: 96)
Drupal\recurring_events_registration\Entity\Registrant->postSave() (Line: 563)
Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 781)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save() (Line: 489)
Drupal\recurring_events_registration\Form\RegistrantForm->save()
call_user_func_array() (Line: 129)

Proposed resolution

Make the email base field required in Registrant::baseFieldDefinitions().

CommentFileSizeAuthor
#7 after.png109.34 KBkul.pratap
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Issue summary: View changes
chrisla’s picture

This was discussed in https://www.drupal.org/project/recurring_events/issues/3090286 with no resolution.

I propose since email address is required for registering and triggers errors if not present, it makes sense to make it required. More functionality can be added for custom solutions where email is not required.

dhruv.mittal’s picture

Assigned: Unassigned » dhruv.mittal

dhruv.mittal’s picture

Assigned: dhruv.mittal » Unassigned
Status: Active » Needs review

I have created MR that is solving the issue.
Also I noticed that if once a registration form is generated a error then it's status will be in pending status and when I try to delete the event series related to registrant it produces same error.
And the given MR solves this too. Please review and let me know if any assistance requires.
Thank you.

kul.pratap’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new109.34 KB

The MR resolved the error, so moving this to RTBC.

Attaching a screenshot for reference.

pfrenssen’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for working on this!

Instead of adding additional code to the form validate handler, let's instead mark the field as required in Registrant::baseFieldDefinitions() as was proposed in the issue summary.

By doing this we will inform Drupal that the field is required. Drupal will then take care of the form validation for us. Also it will do some other helpful things like marking the field as required, support entity validation etc.

We do not need to make any changes to the form, it will all be handled automatically :)

dhruv.mittal’s picture

Status: Needs work » Needs review

Please review

sagartiwari’s picture

Assigned: Unassigned » sagartiwari

I am reviewing this issue.

sagartiwari’s picture

Hello, I have verified the issue MR https://git.drupalcode.org/project/recurring_events/-/merge_requests/143... given in comment #9 fixes the issue. It adds a required validation on the Email Address field which prevents the page to encounter the error.

Thanks.

sagartiwari’s picture

Assigned: sagartiwari » Unassigned
Status: Needs review » Reviewed & tested by the community

plopesc made their first commit to this issue’s fork.

  • plopesc committed 4098b102 on 2.0.x authored by dhruv.mittal
    Issue #3478268: Fatal error when registering for event without entering...

  • plopesc committed 4fede3af on 3.0.x authored by dhruv.mittal
    Issue #3478268: Fatal error when registering for event without entering...
plopesc’s picture

Status: Reviewed & tested by the community » Fixed

MR merged and cherry-picked into 3.0.x. Thank you!

Status: Fixed » Closed (fixed)

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