Guest User

Untitled

a guest
Jul 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. class Default_View_Helper_FormDate extends Zend_View_Helper_FormElement
  4. {
  5. public function formDate ($name, $value = null, $attribs = null)
  6. {
  7. // if the element is rendered without a value,
  8. // show today's date
  9.  
  10. if ($value === null)
  11. {
  12. $value = date('Y-m-d');
  13. }
  14.  
  15. list($year, $month, $day) = split('-', $value); // hardcode the year as 2009
  16.  
  17. // build select options
  18.  
  19. $date = new Zend_Date();
  20.  
  21. $dayOptions = array();
  22. for ($i = 1; $i < 32; $i ++)
  23. {
  24. $idx = str_pad($i, 2, '0', STR_PAD_LEFT);
  25. $dayOptions[$idx] = str_pad($i, 2, '0', STR_PAD_LEFT);
  26. }
  27.  
  28. $monthOptions = array();
  29. for ($i = 11; $i < 13; $i ++)
  30. {
  31. $date->set($i, Zend_Date::MONTH);
  32. $idx = str_pad($i, 2, '0', STR_PAD_LEFT);
  33. $monthOptions[$idx] = $date->toString('MMMM');
  34. }
  35.  
  36. $yearOptions = array();
  37. for ($i = 1970; $i < 2031; $i ++)
  38. {
  39. $yearOptions[$i] = $i;
  40. }
  41.  
  42. // return the 3 selects separated by a space
  43.  
  44. return
  45. $this->view->formSelect(
  46. $name . '_month',
  47. $month,
  48. $attribs,
  49. $monthOptions) . ' ' .
  50. $this->view->formSelect(
  51. $name . '_day',
  52. $day,
  53. $attribs,
  54. $dayOptions) . ' ' .
  55. $this->view->formSelect(
  56. $name . '_year',
  57. $year,
  58. $attribs,
  59. $yearOptions
  60. );
  61. }
  62. }
Add Comment
Please, Sign In to add comment