THELIA Forum

Welcome to the THELIA support and discusssion forum

Offline


Hello Thelia,
how can I change cellphone to be a required field in a registration form? I see that cellphone has "required" => false, in AddressCreateForm. Should I have to create a new module and use hooks for it? If so, how can I proceed that? Or is there some easier way?

Thank you in advance.

Best,
David M.

Last edited by davidm (10-11-2021 09:12:34)


Thelia version 2.4.4.

Offline


Hi,

I guess the easiest way is to change the register.html template in your theme to mark the cellphone input field as required. Using this method the validation will be performed on the client side.

To be on the safe side you should probably make the validation on the server side via the Symfony form validator. To do this you'll have to create a listener in a module to redefine the cellphone field on the

TheliaEvents::FORM_BEFORE_BUILD.thelia.front.customer.create

  form event.

Offline


Hi NOG,
Thank you for your response. I've done what you suggested. I'm trying to add some dummy data to an input through event listener, but debugging an event, I got

$event->getForm(), form = null

Screenshot from debug session:
https://www.dropbox.com/s/b07d50fvhyr75 … 9.png?dl=0

Last edited by davidm (09-11-2021 17:46:55)


Thelia version 2.4.4.

Offline


Can you listen to the FORM_AFTER_BUILD instead ?

TheliaEvents::FORM_AFTER_BUILD . '.thelia_customer_create' => ['requireCellphone', 128]

Offline


I tried with

TheliaEvents::FORM_AFTER_BUILD . '.thelia_customer_create' => ['requireCellphone', 128]

but I got 500 (An error occurred).


Thelia version 2.4.4.

Offline


Now it works, I had a wrong parameter in

$formBuilder->add()

Thank you NOG!


Thelia version 2.4.4.

Offline


Bravo wink

Please mark the post as [RESOLVED]

P.S. : what IDE are you using ?

Last edited by Nog (10-11-2021 08:49:00)

Offline


I’m using PhpStorm with Xdebug 3.


Thelia version 2.4.4.

Offline


There is actually very nice plugin ForcePhone for my case: https://github.com/thelia-modules/ForcePhone


Thelia version 2.4.4.

Offline


Oh my... Good catch about the plugin.
Should have started to look in the Thelia modules repositories sad