Jump to content

Recommended Posts

Posted

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.

Posted

I meant something else. You're using FormBuilder, which offers four different options (A, B, C, and D) to embed your form into a template or page.
For example, if you use option D, you're implementing custom code, and the rendering is not handled by FormBuilder. In that case, the hook would have no effect.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...