zend 插件 html5,html - Zend HTML5 Form element types - Stack Overflow

Here is what I did to solve for XML5 elements.

First I created a custom form element on: library/Custom/Form/Element/Html5.php

/** Zend_Form_Element_Xhtml */

require_once 'Zend/Form/Element/Xhtml.php';

class Custom_Form_Element_Html5 extends Zend_Form_Element_Xhtml

{

public $helper = 'formHtml5';

}

Then I created a custom view helper on: library/Custom/View/Helper/FormHtml5.php

/**

* Abstract class for extension

*/

require_once 'Zend/View/Helper/FormElement.php';

/**

* Helper to generate an "Html5" element

*

*/

class Custom_View_Helper_FormHtml5 extends Zend_View_Helper_FormElement

{

public function formHtml5($name, $value = null, $attribs = null)

{

$info = $this->_getInfo($name, $value, $attribs);

extract($info); // name, value, attribs, options, listsep, disable

// build the element

$disabled = '';

if ($disable) {

// disabled

$disabled = ' disabled="disabled"';

}

// XHTML or HTML end tag?

$endTag = ' />';

if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {

$endTag= '>';

}

$xhtml = '

. ' type="' . (($attribs['type'])?($this->view->escape($attribs['type'])):'text') . '"'

. ' name="' . $this->view->escape($name) . '"'

. ' id="' . $this->view->escape($id) . '"'

. ' value="' . $this->view->escape($value) . '"'

. $disabled

. $this->_htmlAttribs($attribs)

. $endTag;

return $xhtml;

}

}

Then in the Form I added this:class Application_Form_UserBasic extends Zend_Form

{

public function init()

{

// this will tell zf to look for custom helpers on your custom library

$view = $this->getView();

$view->addHelperPath(APPLICATION_PATH.'/../library/Custom/View/Helper/', 'Custom_View_Helper');

/* Some other code */

$email = new Custom_Form_Element_Html5('email');

$email->setAttribs(array( 'type' => 'email'));

/* Your other elements*/

$this->addElements(array(

$email, /* your other elements */

));

}

}

Do not forget to add this line to your application.ini file in case you have not done so:

autoloaderNamespaces[] = "Custom_"

I hope it helps somebody.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值