I added a submit function in the form_alter hook when inserting a node:
$form['actions']['save_as_draft'] = [
'#type' => 'submit',
'#value' => t('Save as Draft'),
'#submit' => ['save_as_draft'],
'#limit_validation_errors' => [],
];
In the save_as_draft() function, I want to get the address value from the form state, but there are no values (except for the additional submit button).
function save_as_draft(&$form, Drupal\Core\Form\FormStateInterface $form_state) {
var_dump($form_state->getValue('field_address')); // outputs NULL
var_dump($form_state->get('field_address')); // outputs NULL
var_dump($form['field_address']['widget'][0]['value']['#value']); // outputs 'Address value'
var_dump(array_keys($form_state->getValues())); // outputs { [0]=> "save_as_draft" [1]=> "op" }
}
How can I get the form_state values in this alternative submit function without validating the whole form?
Is there another way of retrieving the form values instead of digging through the widget arrays?
$form_state->getValues()
to see all values ?