将值添加到Symfony 2上生成的文本框中

时间:2013-01-31 18:57:47

标签: symfony

有这个:

echo $view['form'] -> row($form["codelist"], array(
    //widget
    "widgetArgs" => array(
        "attr" => array(
            'class' => 'input-xlarge tooltipRight', 
            'id' => "gift_codelist"
            ),
            "tooltip"=>"gift.tooltip.codelist",
            "translation_domain" =>"brand"


         ),
   "labelArgs" => array(
        "label_attr" => array(
            'class' => 'control-label', 
        )) ,"rowType"=>2
      )
  );

如何向该文本框添加初始值?

1 个答案:

答案 0 :(得分:2)

如果要在字段中添加实际值,可以使用value属性:

"attr" => array(
        'class' => 'input-xlarge tooltipRight', 
        'id' => "gift_codelist",
        'value' => "Your initial value"
        )

但是,如果您使用的是HTML5并且只是希望向用户提供提示,那么最好使用placeholder

"attr" => array(
        'class' => 'input-xlarge tooltipRight', 
        'id' => "gift_codelist",
        'placeholder' => "Your initial value"
        )

http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute