How to set the value of a hidden field using form_set_value? In form validation I have to set value of a hidden field. I tried like below

\Drupal::formBuilder()-&gt;setValue($form['maintenance_type'], 'R', $form_state);

form_set_value($form['maintenance_type'], 'I', $form_state);
Insert the the value in $form_state:

$form_state-&gt;set('store_value', 1);


And then later for example in submitForm():

$value = $form_state-&gt;get('store_value');


Don't use getValue() or setValue(), because this is for submitted values.

If you are migrating more forms from D7 to D8, use this as reference:

Use this as reference