I’ve created a form with Form Api in a custom module.
I send datas with post
method to a web service.
In buildForm()
$form['mode'] = array( '#type' => 'hidden', '#value' => 'INTERACTIVE', ); $form['amount'] = array( '#type' => 'textfield' ); $form['signature'] = array( '#type' => 'hidden', // here is the field I need to set its value on submit because its value depends on other field. '#value' => '' ); $form['#action'] = 'https://url-webservices.fr/‘
It works. But I need to set value to hidden fields 'signature'
on submit.
How can I set value to hidden field and send them with form with post method ?
Something like this but it doesn’t work :
in submitForm() form_state->setValue('signature', $signature);
I’ve studied some examples and I can do that :
In validateForm()
$signature = 'string-to-send'; $form_state->setValue('signature', $signature); $form_state->setRebuild();
And in buildForm()
:
$signature = $form_state->getValue('signature'); $form['signature'] = array( '#type' => 'hidden', '#value' => $signature );
Of course, it works only when page is reloaded when the form is rebuilt. If datas is send to an external URL with POST
method, the field value is empty.