{"id":9853,"date":"2013-03-08T15:09:38","date_gmt":"2013-03-08T09:39:38","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=9853"},"modified":"2013-03-08T15:09:38","modified_gmt":"2013-03-08T09:39:38","slug":"magento-date-time-picker-in-front-end-form","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/magento-date-time-picker-in-front-end-form\/","title":{"rendered":"Magento date time picker in front end form"},"content":{"rendered":"<p>Some times there is requirement of date time picker in your frontend form. Mostly for this developers usually use jQuery. But it is not a right way to do this. Magento do have date time picker library which is for admin form only. But with some customization we can use it in our frontend form as well. Following steps you need to follow to achieve this.<\/p>\n<p>First of all open your form&#8217;s layout xml file (app\/design\/frontend\/your_package\/your_theme\/layout\/your_layout.xml) and put following code in it :<\/p>\n<p>[php]<\/p>\n<p>&lt;reference name=&quot;head&quot;&gt;<\/p>\n<p>&lt; action method=&quot;addItem&quot;&gt;&lt;type&gt;js_css&lt;\/type&gt;&lt;name&gt;calendar\/calendar-win2k-1.css&lt;\/name&gt;&lt;params\/&gt;&lt;!&#8211;&lt;if\/&gt;&lt;condition&gt;can_load_calendar_js&lt;\/condition&gt;&#8211;&gt;&lt;\/action&gt;<\/p>\n<p>&lt; action method=&quot;addItem&quot;&gt;&lt;type&gt;js&lt;\/type&gt;&lt;name&gt;calendar\/calendar.js&lt;\/name&gt;&lt;!&#8211;&lt;params\/&gt;&lt;if\/&gt;&lt;condition&gt;can_load_calendar_js&lt;\/condition&gt;&#8211;&gt;&lt;\/action&gt;<\/p>\n<p>&lt; action method=&quot;addItem&quot;&gt;&lt;type&gt;js&lt;\/type&gt;&lt;name&gt;calendar\/lang\/calendar-en.js&lt;\/name&gt;&lt;!&#8211;&lt;params\/&gt;&lt;if\/&gt;&lt;condition&gt;can_load_calendar_js&lt;\/condition&gt;&#8211;&gt;&lt;\/action&gt;<\/p>\n<p>&lt; action method=&quot;addItem&quot;&gt;&lt;type&gt;js&lt;\/type&gt;&lt;name&gt;calendar\/calendar-setup.js&lt;\/name&gt;&lt;!&#8211;&lt;params\/&gt;&lt;if\/&gt;&lt;condition&gt;can_load_calendar_js&lt;\/condition&gt;&#8211;&gt;&lt;\/action&gt;<\/p>\n<p>&lt;\/reference&gt;<\/p>\n<p>[\/php]<\/p>\n<p>Till now all the required js files are added in your form&#8217;s layout. Now put the following code at the top of your form&#8217;s template file (aa\/design\/frontend\/your_package\/your_theme\/template\/your_module\/form.phtml).<\/p>\n<p>[php]<\/p>\n<p>&lt;script type=&quot;text\/javascript&quot;&gt;<\/p>\n<p>\/\/&lt;![CDATA[<\/p>\n<p>enUS = {&quot;m&quot;:{&quot;wide&quot;:[&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,<br \/>\n&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;],&quot;abbr&quot;:[&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,<br \/>\n&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;]}}; \/\/ en_US locale reference<br \/>\nCalendar._DN = [&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;]; \/\/ full day names<\/p>\n<p>Calendar._SDN = [&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;]; \/\/ short day names<\/p>\n<p>Calendar._FD = 1; \/\/ First day of the week. &quot;0&quot; means display Sunday first, &quot;1&quot; means display Monday first, etc.<\/p>\n<p>Calendar._MN = [&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,<br \/>\n&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;]; \/\/ full month names<\/p>\n<p>Calendar._SMN = [&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;]; \/\/ short month names<\/p>\n<p>Calendar._am = &quot;AM&quot;; \/\/ am\/pm<\/p>\n<p>Calendar._pm = &quot;PM&quot;;<\/p>\n<p>\/\/ tooltips<\/p>\n<p>Calendar._TT = {};<\/p>\n<p>Calendar._TT[&quot;INFO&quot;] = &quot;About the calendar&quot;;<\/p>\n<p>Calendar._TT[&quot;ABOUT&quot;] =<\/p>\n<p>&quot;DHTML Date\/Time Selector\\n&quot; +<\/p>\n<p>&quot;(c) &lt;a href=&quot;http:\/\/dynarch.com\/&quot; target=&quot;_blank&quot;&gt;dynarch.com&lt;\/a&gt; 2002-2005 \/ Author: Mihai Bazon\\n&quot; +<\/p>\n<p>&quot;For latest version visit:&lt;a href=&quot;http:\/\/www.dynarch.com\/projects\/calendar\/%5Cn&quot; target=&quot;_blank&quot;&gt;http:\/\/www.dynarch.com\/projects\/calendar\/\\n&lt;\/a&gt;&quot; +<\/p>\n<p>&quot;Distributed under GNU LGPL. See &lt;a href=&quot;http:\/\/gnu.org\/licenses\/lgpl.html&quot; target=&quot;_blank&quot;&gt;http:\/\/gnu.org\/licenses\/lgpl.html&lt;\/a&gt; for details.&quot; +<\/p>\n<p>&quot;\\n\\n&quot; +<\/p>\n<p>&quot;Date selection:\\n&quot; +<\/p>\n<p>&quot;- Use the \\xab, \\xbb buttons to select year\\n&quot; +<\/p>\n<p>&quot;- Use the &quot; + String.fromCharCode(0x2039) + &quot;, &quot; + String.fromCharCode(0x203a) + &quot; buttons to select month\\n&quot; +<\/p>\n<p>&quot;- Hold mouse button on any of the above buttons for faster selection.&quot;;<\/p>\n<p>Calendar._TT[&quot;ABOUT_TIME&quot;] = &quot;\\n\\n&quot; +<\/p>\n<p>&quot;Time selection:\\n&quot; +<\/p>\n<p>&quot;- Click on any of the time parts to increase it\\n&quot; +<\/p>\n<p>&quot;- or Shift-click to decrease it\\n&quot; +<\/p>\n<p>&quot;- or click and drag for faster selection.&quot;;<\/p>\n<p>Calendar._TT[&quot;PREV_YEAR&quot;] = &quot;Prev. year (hold for menu)&quot;;<\/p>\n<p>Calendar._TT[&quot;PREV_MONTH&quot;] = &quot;Prev. month (hold for menu)&quot;;<\/p>\n<p>Calendar._TT[&quot;GO_TODAY&quot;] = &quot;Go Today&quot;;<\/p>\n<p>Calendar._TT[&quot;NEXT_MONTH&quot;] = &quot;Next month (hold for menu)&quot;;<\/p>\n<p>Calendar._TT[&quot;NEXT_YEAR&quot;] = &quot;Next year (hold for menu)&quot;;<\/p>\n<p>Calendar._TT[&quot;SEL_DATE&quot;] = &quot;Select date&quot;;<\/p>\n<p>Calendar._TT[&quot;DRAG_TO_MOVE&quot;] = &quot;Drag to move&quot;;<\/p>\n<p>Calendar._TT[&quot;PART_TODAY&quot;] = &#8216; (&#8216; + &quot;Today&quot; + &#8216;)&#8217;;<\/p>\n<p>\/\/ the following is to inform that &quot;%s&quot; is to be the first day of week<\/p>\n<p>Calendar._TT[&quot;DAY_FIRST&quot;] = &quot;Display %s first&quot;;<\/p>\n<p>\/\/ This may be locale-dependent. It specifies the week-end days, as an array<\/p>\n<p>\/\/ of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1<\/p>\n<p>\/\/ means Monday, etc.<\/p>\n<p>Calendar._TT[&quot;WEEKEND&quot;] = &quot;0,6&quot;;<\/p>\n<p>Calendar._TT[&quot;CLOSE&quot;] = &quot;Close&quot;;<\/p>\n<p>Calendar._TT[&quot;TODAY&quot;] = &quot;Today&quot;;<\/p>\n<p>Calendar._TT[&quot;TIME_PART&quot;] = &quot;(Shift-)Click or drag to change value&quot;;<\/p>\n<p>\/\/ date formats<\/p>\n<p>Calendar._TT[&quot;DEF_DATE_FORMAT&quot;] = &quot;%b %e, %Y&quot;;<\/p>\n<p>Calendar._TT[&quot;TT_DATE_FORMAT&quot;] = &quot;%B %e, %Y&quot;;<\/p>\n<p>Calendar._TT[&quot;WK&quot;] = &quot;Week&quot;;<\/p>\n<p>Calendar._TT[&quot;TIME&quot;] = &quot;Time:&quot;;<\/p>\n<p>\/\/]]&gt;<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p>&lt;!&#8211; put this textbox at your desired position &#8211;&gt;<\/p>\n<p>&lt; span class=&quot;label&quot;&gt;Date&lt;\/span&gt;<\/p>\n<p>&lt; input name=&quot;date&quot; id=&quot;date&quot; type=&quot;text&quot;&gt;<\/p>\n<p>&lt; img src=&quot;&lt;strong&gt;&lt;?php&lt;\/strong&gt;echo $this-&gt;getSkinUrl(&lt;strong&gt;&#8217;images\/grid-cal.gif'&lt;\/strong&gt;) &lt;strong&gt;?&gt;&lt;\/strong&gt;&quot; alt=&quot;&quot; id=&quot;date_trig&quot; title=&quot;Date selector&quot;&gt;<\/p>\n<p>&lt; \/div&gt;&lt;script type=&quot;text\/javascript&quot;&gt;<\/p>\n<p>Calendar.setup({<\/p>\n<p>inputField : &quot;date&quot;,<\/p>\n<p>ifFormat : &quot;%e\/%m\/%y&quot;,<\/p>\n<p>button : &quot;date_trig&quot;,<\/p>\n<p>showsTime: false,<\/p>\n<p>align : &quot;Bl&quot;,<\/p>\n<p>singleClick : true<\/p>\n<p>});<\/p>\n<p>&lt; \/script&gt;<\/p>\n<p>[\/php]<\/p>\n<p>Now clear the magento cache. If calendar image is not rendering then check its path.<\/p>\n<p>That&#8217;s it. Hope this will help you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some times there is requirement of date time picker in your frontend form. Mostly for this developers usually use jQuery. But it is not a right way to do this. Magento do have date time picker library which is for admin form only. But with some customization we can use it in our frontend form [&hellip;]<\/p>\n","protected":false},"author":59,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":18},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/9853"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=9853"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/9853\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=9853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=9853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=9853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}