我正在使用CakePHP
进行一些练习,并且我想从我创建的表单中删除我通常会避免的HTML
元素,如<legend>
和<fieldset>
Form->create()
。
我看到有这样的方式:
<?php
echo $this->Form->create('User',
array (
'action' => 'login',
'inputDefaults' => array (
'fieldset' => false,
'legend' => false
)
));
echo $this->Form->inputs(array (
/*'legend' => __('Login', true),*/
'username',
'password'
));
echo $this->Form->end('Login');
?>
如果我写这个<legend>
,<fieldset>
将会显示。
是否存在一些删除它们的特定选项?
<form accept-charset="utf-8" action="/site.com/users/login" method="post" id="UserLoginForm">
<div style="display: none;"><input type="hidden" value="POST" name="_method"></div>
<!-- hoto to remove this --><fieldset><legend>New User</legend><!-- end of removing -->
<div class="input text required">
<label for="UserUsername">Username</label><input type="text" id="UserUsername" maxlength="255" name="data[User][username]">
</div>
<div class="input password required"><label for="UserPassword">Password</label><input type="password" id="UserPassword" name="data[User][password]"></div>
<!-- hoto to remove this --></fieldset><!-- end of removing -->
<div class="submit"><input type="submit" value="Accedi"></div>
</form>
答案 0 :(得分:4)
inputs()函数是1.3的新功能,允许您将字段捆绑在一个函数中并稍微整理一下。以下是如何杀死字段集和图例:
echo $this->Form->input(array(
'legend' => false,
'fieldset' => false,
'username',
'password'
));
答案 1 :(得分:2)
问题是
echo $this->Form->inputs(array (
/*'legend' => __('Login', true),*/
'username',
'password'
));
用来代替
echo $this->Form->input('username');
echo $this->Form->input('password');
来自我在book.cakephp.org
上阅读的示例答案 2 :(得分:0)
我从未见过表单助手生成<fieldset>
和<legend>
。这将是您观点的一部分。典型的视图文件(/app/views/items.ctp)
<?php echo $this->Form->create('Item');?>
<fieldset> <!-- remove this from your view (CTP) file -->
<legend><?php __('Add Item'); ?></legend>
<?php
echo $this->Form->input('item_id');
echo $this->Form->input('name');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
如您所见,<fieldset>
和<legend>
是视图中HTML的一部分。只需将其从标记中删除即可。 FormHelper仅为FORM和一些实用程序输入生成标记。