Syntax to use form_alter with array in name attribute I would like to modify some custom fields with form_alter in a contact form.

I know for example how to change placeholder for this "name" field  :
Note : I removed all the unnecessary html elements to make my question clearer 

&lt;input name="name" &gt;


In form_alter :

$form['name']['#attributes']['placeholder'] = t('Nom');
$form['name']['#title_display'] = 'invisible';


But I don’t find the correct syntax when the name is with an array like :

&lt;input name="field_prenom[0][value]" &gt;


How to use form_alter with field_prenom[0][value] ?

I’ve tried this but it doesn’t work :

$form['field_prenom']['0']['value']['#attributes']['placeholder'] = t('Prénom');
Why are you using field's attribute 'name' instead of it's machine name 'field_prenom'? If you check in 'kint' you would get the hierarchy of 'placeholder' attribute.

You can update placeholder using form_alter only. Check the below example.

$form['field_name']['widget'][0]['value']['#placeholder'] = 'Nom';