1

In form validation I have to set value of a hidden field. I tried like below

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

form_set_value($form['maintenance_type'], 'I', $form_state);
2
  • $form_state->set('store_value', 1); cant u use this ?? Aug 17 '16 at 6:19
  • I have just found the same will update the post. @ShreyaShetty Put it as an answer
    – Sri Harsha
    Aug 17 '16 at 6:23
2

Insert the the value in $form_state:

$form_state->set('store_value', 1);

And then later for example in submitForm():

$value = $form_state->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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.