I am building a form for an inscription, so I want to have a token in a link in the mail to the subscriber, on which they click, to validate their email.
So I tried to create a hidden field and to feed it through addHookBefore.
It did not work, so I tried to create the field and feed it still through addHookBefore I did not work, neither.
Here is my function :
$forms->addHookBefore('FormBuilderProcessor::renderReady', function($e){
$processor = $e->object; // FormBuilderProcessor instance
$form = $e->arguments(0);
if($processor->formName == 'inscription') {
$field = $this->modules->get('InputfieldHidden');
$field->attr('id+name', 'verif-token');
$field->label = "Token de vérification";
$field->value = bin2hex(random_bytes(32));
$field->required = true;
$form->add($field);
}
});
My field in the link inside the mail is empty or I have the fielname between brackets. Maybe I miss a detail or my strategy is wrong.