【问题标题】:why don't set the placeholder attribute for contact field?为什么不为联系人字段设置占位符属性?
【发布时间】:2014-05-30 07:16:40
【问题描述】:

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

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

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

【问题讨论】:

    标签: drupal-7 drupal-hooks form-api


    【解决方案1】:

    我在代码中添加了这一行,问题就解决了:

     $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');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-27
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 2013-01-17
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多