这是我在hook_form_alter
函数中用于设置占位符属性的代码:
if ($form_id == 'contact_site_form') {
$form['name']['#title'] = t('name/family name');
$form['name']['#attributes']['placeholder'] = t('Enter your name');
}
为什么不为联系人字段设置占位符属性?
答案 0 :(得分:0)
我在代码中添加了这一行,问题解决了:
$form['name']['#default_value'] ='';
编辑的代码是:
if ($form_id == 'contact_site_form') {
$form['name']['#title'] = t('name/family name');
$form['name']['#default_value'] ='';
$form['name']['#attributes']['placeholder'] = t('Enter your name');
}