2013-03-25 22 views
2

我正在使用下面的代碼來生成一個表單。如何使表單輸入並排且只有一個標籤? CakePHP

echo $this->Form->create('External'); 
echo $this->Form->input('program_title', array('label' => 'Program Name')); 
echo $this->Form->input('reference_code', array('label' => 'Reference No.')); 
echo $this->Form->input('date_received', array('label' => 'Date Received', 'type' => 'date')); 
echo $this->Form->input('date_released', array('value' => date('Y-m-d'), 'type' => 'hidden')); 
echo $this->Form->input('inclusive_date_start', array('label' => 'Inclusive Date Start', 'type' => 'date')); 
echo $this->Form->input('inclusive_date_end', array('label' => 'Inclusive Date End', 'type' => 'date')); 
echo $this->Form->input('time_start', array('label' => 'Time Start', 'type' => 'time')); 
echo $this->Form->input('time_end', array('label' => 'Time End', 'type' => 'time')); 
echo $this->Form->end('Add Program'); 

,它創造了以下內容:

Original Image

我如何讓它出現像這樣的呢?

Edited Image

第二圖像剛編輯,所以我可以告訴你我多麼希望它看起來像。小心點亮一些光線?

回答

0

在CakePHP中,您並不總是必須爲表單元素添加一個標籤,從而允許您執行自定義分組和位置。

下面是一個簡單的例子,說明如何使用代碼完成它。爲了簡單起見,我將所有內容都放在了PHP中,但是您也可以跳出PHP並編寫實際的HTML。請注意使用'label' => false

echo $this->Form->create('External'); 
echo $this->Form->input('program_title', array('label' => 'Program Name')); 
echo $this->Form->input('reference_code', array('label' => 'Reference No.')); 
echo $this->Form->input('date_received', array('label' => 'Date Received', 'type' => 'date')); 
echo $this->Form->input('date_released', array('value' => date('Y-m-d'), 'type' => 'hidden')); 
//Custom HTML code 
echo '<div>Inclusive Date</div>'; 
echo '<div>'; 
echo '<div style="float: left;"> 
echo $this->Form->input('inclusive_date_start', array('label' => false, 'type' => 'date')); 
echo '</div>'; 
echo '<div style="float: left;">-</div>'; 
echo '<div style="float: left;">'; 
echo $this->Form->input('inclusive_date_end', array('label' => false, 'type' => 'date')); 
echo '</div>' 
echo '<div style="clear: both;"></div>'; 
echo '</div>'; 
//Back to normal PHP 
echo $this->Form->input('time_start', array('label' => 'Time Start', 'type' => 'time')); 
echo $this->Form->input('time_end', array('label' => 'Time End', 'type' => 'time')); 
echo $this->Form->end('Add Program'); 
相關問題