0

这是我在hook_form_alter函数中用于设置占位符属性的代码:

        if ($form_id == 'contact_site_form') {
            $form['name']['#title'] = t('name/family name');
            $form['name']['#attributes']['placeholder'] = t('Enter your name');
        }

为什么不为联系人字段设置占位符属性?

4

1 回答 1

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');
}
于 2014-05-30T12:55:30.973 回答