I have form alter for the user_register_form
which is called.
In this hook, I try to set a default value for a textfield but it doesn't work.
I've tried all the syntax possible #default_value
, #value
, value
, default_value
, event in the attributes array.
This is my code.
function pre_registration_form_user_register_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['field_code_postal']['#cache']['max-age'] = 0;
$form['field_code_postal']['#default_value'] = 'COUCOU';
$form['field_code_postal']['#value'] = 'COUCOU';
$form['field_code_postal']['value'] = 'COUCOU';
$form['field_code_postal']['value']['#value'] = 'COUCOU';
$form['field_code_postal']['value']['#default_value'] = 'COUCOU';
$form['field_code_postal']['value']['value'] = 'COUCOU';
$form['field_code_postal']['value']['default_value'] = 'COUCOU';
$form['field_code_postal']['default_value'] = 'COUCOU';
$form['field_code_postal']['#attributes']['value'] = 'COUCOU1';
$form['field_code_postal']['#attributes']['#value'] = 'COUCOU2';
$form['field_code_postal']['#attributes']['default_value'] = 'COUCOU3';
$form['field_code_postal']['#attributes']['#default_value'] = 'COUCOU4';
}
How can I set a default value?