2013-01-31 53 views
0

生成的值到文本框有了這個:添加上的Symfony 2

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 
    ) 
); 

你如何初始值添加到文本框?

+0

這是一個非常骯髒的方式手工形式或者不是你在fullstack使用Symfony的? – Schwierig

+0

@Schwierig你爲什麼說它很髒?他似乎在使用PHP模板引擎而不是Twig,這是一種「不同」的方式,但仍然得到支持。 – cheesemacfly

+0

我用來在類型中生成我的表單,而不是直接在twig/php中生成。所以我通常不會在渲染中遇到這個巨大的數組。 對不起:) – Schwierig

回答

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