我正在使用以下代码生成表单。
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');
它创造了以下内容:
如何让它像这样出现?
第二张图片刚刚编辑完毕,我可以告诉你我想要的样子。小心点亮?
答案 0 :(得分: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');