gpt4 book ai didi

zend-framework - 如何摆脱 Zend_Form dl、dt、dd 标签?

转载 作者:行者123 更新时间:2023-12-04 04:28:27 32 4
gpt4 key购买 nike

我想去掉我的 Zend_Form 的定义列表格式.这是我要的布局:

<form>
<p>
<label for="email" class="required">Your email address:</label>
<input type="text" name="email" id="email" value="">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Subscribe">
</p>
<input type="hidden" name="active" value="true" id="active">
<input type="hidden" name="signupDate" value="" id="signupDate">
</form>

为了获得此布局,我需要对表单做什么?
class Default_Form_Subscribe extends Zend_Form
{
public function init()
{
$this->setMethod('post');

$this->addElement('text', 'email', array(
'label' => 'Email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress')
));

$this->addElement('submit', 'submit', array(
'label' => 'Subscribe',
'ignore' => true
));

$this->addElement('hidden', 'active', array(
'value'=>'true'
));
$this->addElement('hidden', 'signupDate', array(
'value' => Zend_Date::now()->toString('YYYY-MM-dd')
));
}
}

最佳答案

啊,打败了我......我采用了创建可应用于特定元素的自定义定义的方法。还必须重置表单本身的装饰器以删除默认的“dl”包装器,似乎完全符合您的需要:

class Default_Form_Subscribe extends Zend_Form
{
public function init()
{
$this->setMethod('post');

// reset form decorators to remove the 'dl' wrapper
$this->setDecorators(array('FormElements','Form'));

// custom decorator definition for form elements
$customElementDecorators = array(
'ViewHelper',
'Errors',
array(
'Description',
array('tag' => 'p','class' => 'description')
),
array(
'Label',
array('separator' => ' ')
),
array(
array('data' => 'HtmlTag'),
array('tag' => 'p')
)
);

$this->addElement('text', 'email', array(
'label' => 'Email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress'),
'decorators' => $customElementDecorators
));

$this->addElement('submit', 'submit', array(
'label' => 'Subscribe',
'ignore' => true,
'decorators' => $customElementDecorators
));

$this->addElement('hidden', 'active', array(
'value'=>'true',
'decorators' => array('ViewHelper')
));
$this->addElement('hidden', 'signupDate', array(
'value' => Zend_Date::now()->toString('YYYY-MM-dd'),
'decorators' => array('ViewHelper')
));
}
}

关于zend-framework - 如何摆脱 Zend_Form dl、dt、dd 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1935480/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com