2016-02-20 126 views
0

我使用Zend Framework 2和骨架應用程序創建表單。Zend Framework 2骨架佈局

我想我的佈局複製默認的例子:

enter image description here

正如你可以在上面看到,該表單輸入延伸到屏幕的寬度。該代碼產生這(僅使用電子郵件地址字段爲例):

<div class="form-group"> 
    <label for="exampleInputEmail1">Email address</label> 
    <input type="email" placeholder="Email" id="exampleInputEmail1" class="form-control"> 
</div> 

我想同樣的結果,當我使用Zend Framework 2(框架應用程序)添加自己的表單元素髮生。但是,當我添加元素:

$this->add(array(
     'name' => 'campaign_code', 
     'type' => 'Text',    
     'options' => array(
      'label' => 'Campaign Code', 
     ), 
     'attributes' => array(
      'class' => 'form-control', 
     )     
    )); 

生成的HTML是:

<div class="form-group"> 
    <label> 
     <span>Campaign Code</span> 
     <input class="form-control" type="text" name="campaign_code"> 
    </label> 
</div> 

,導致:

enter image description here

通知之label標籤是如何圍繞spaninput元素?我不想那樣。我希望label標籤可以像第一個html示例中那樣關閉。

回答

0

表單視圖幫助器在呈現表單中的元素時非常智能。

添加的id屬性具有相應的元件

$this->add(array(
    'name' => 'campaign_code', 
    'type' => 'Text',    
    'options' => array(
     'label' => 'Campaign Code', 
    ), 
    'attributes' => array(
     'class' => 'form-control', 
     'id' => 'your_id', 
    )     
));