zend 插件 html5,html - Zend HTML5 Form element types - Stack Overflow
发布日期:2022-02-03 04:38:41 浏览次数:9 分类:技术文章

本文共 2000 字,大约阅读时间需要 6 分钟。

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.

转载地址:https://blog.csdn.net/weixin_30596151/article/details/117942556 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:html嵌入视频mp4视频无法播放,html中嵌入mp4格式视频无法播放
下一篇:语音播报 android,Android 语音播报 文字转语音

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月18日 07时42分45秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章