Function introduction: Today I want to make a background form element to display the date and time. At first I thought it has the same function as the form element tag (1) used in the Magento background. I only need to set the type type to date, but after setting it, start I couldn't figure it out, so I thought about loading some js packages in the background and using external js plug-ins to implement this function. Later, I asked the company's technical expert and said that I can directly call the magento system's built-in one. Here is a record of how to achieve this. Function, the rendering is as follows:
The code is as follows, add the code in Form.php as follows:
<code>$fieldset->addField( 'endtime', 'date',//type类型 array( 'label' => Mage::helper('blog')->__('Endtime'), 'required' => true,//是否为必选项 'name' => 'endtime', 'image' => $this->getSkinUrl('images/grid-cal.gif'),//增加图标 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),//时间格式 ));</code>
Some additional notes:
1. Sometimes if you want to load some js in the background form, you can also add it in array() Add: 'after_element_html' => "".
2. To add css, you can first write the css style externally, $style="width:6px;text-align:center;" and then add: 'style'=> $style,//Define the css of the button. You can also write it directly, for example: 'style' => 'width:700px; height:500px;'.
<code>$fieldset->addField( 'endtime', 'date',//类型,可以为text,datetime,time,submit,select,radio,checkbox,password,link,label,image,file... array( 'label' => Mage::helper('blog')->__('Endtime'), 'required' => true,//是否为必选项 'style'=> $style,//定义按钮的css . 'name' => 'endtime', 'image' => $this->getSkinUrl('images/grid-cal.gif'),//添加图片 'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT), 'after_element_html' => "<script type='text/javascript'>//js代码</script>"。 ));</code>
The above introduces the Magento background form element tag 2-display date, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.