TransWikia.com

How to validate email address entered during checkout on Craft Commerce?

Craft CMS Asked by Laurence Cope on April 10, 2021

The craft commerce templates have too many checkout steps for us in practice. So I have combined them.

I have moved the email field into the Address page.

But I can submit this form without ever entering an email. There is no validation on it (at this stage anyway).

How can I validate the email at this point please?

To validate the address I use this, but when adding email to it there is an error because email is not part of the Address.

Event::on(
    Address::class,
    Model::EVENT_DEFINE_RULES,
    function(DefineRulesEvent $event) {
        $rules = $event->rules;
        $rules[] = [['firstName', 'lastName'], 'required'];
        $event->rules = $rules;
    }
);

For info, we are not allowing user registration, its guest accounts only. No need to check if a user email exists, or have a login form or a link to checkout as guest. We just need to check the email field has been filled in.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP