ZF2表单中的html

时间:2013-06-26 10:50:04

标签: zend-framework2 zend-form

我想知道如何删除所有形成zend framework 2的HTML自动添加?

我希望每个输入的结果是:

<label for="email" class="required"> Email </ label>
<input type="text" name="email" id="email" value="" class="span5">

而不是这个:

<label>
<span> Email </ span>
<input type="text" name="email" class="span5" value="">
</ label>

我该怎么办?

1 个答案:

答案 0 :(得分:1)

检查表单呈现http://framework.zend.com/manual/2.0/en/modules/zend.form.quick-start.html#rendering

你可以这样做平滑:

// set the needed atributes
$email = new Element\Email('email');
$email->setLabel('Contact Email')
 ->setAttribute('title', 'Please enter your email address')
->setAttribute('id', 'email')
->setAttribute('value', 'Email')
->setAttribute("onfocus", 'if(this.value==\'Email\')this.value=\'\'')
->setAttribute('onblur', 'if(this.value==\'\')this.value=\'Email\'');

// this for rendering in your phtml file
$email = $form->get('emali');
echo $formLabel->openTag() . $name->getOption('label');
echo $formLabel->closeTag();
echo $this->formInput($name);
echo $this->formElementErrors($name);