HTML_QuickForm2 日期元素模板

HTML_QuickForm2 Template for date element

<select id="0-d-0" name="d">
<option value="1">01</option>
...
<option value="31">31</option>
</select>
<select id="1-M-0" name="M">
<option value="1">Jan</option>
...
<option value="12">Dec</option>
</select>
... So on and so on

我相信阅读本文的您会熟悉从 HTML_QuickForm2 返回的元素。

这让我发疯。

近 post 也没有手册可以告诉我如何将其更改为更有用的日期元素...

<input type="date" name="date" value="TODAY" />

哪个浏览器可以很好地显示日历并且简单UI。

我认为模板重新定义是正确的,所以接下来我将向您展示我是如何做到的..

我请任何人告诉我他们是怎么做到的??

Oh QuickForms,你真漂亮。

$form = HTML_QuickForm2_Controller( 'realDate' );

$form = new HTML_FormsFactory(
             new HTML_QuickForm2(
                                 'realDate',
                                  NULL,['name'=>'date','action'=>''], NULL 
                                )
                             );

$date = "2016-05-18";    

$form->addHandler( 'process' , new HTMLProcess() );
$form->addHandler( 'display' , new HTMLDisplay($date) ); // The HACK.
$form->run();

现在控制器的一些 Class 定义等等...

//
class HTMLFormsFactory extends HTML_QuickForm2_Controller_Page{

 public function __construct(){
  parent::__construct( $form );
  $this->HTML = $this->form;
 } 

 public function populateForm(){
  $this->HTML->addDate( 'dater', [ 'id'=>'dater' ] );
 }
}

//
class HTMLProcess implements HTML_QuickForm2_Controller_Action{

 public function perform( HTML_QuickForm2_Controller_Page $page, $name ){
  var_dump( $page->getController()->getValue() );
 }
}

//
class HTMLDisplay extends HTML_QuickForm2_Controller_Action_Display{

 public function __construct($date){ $this->_date = $date; } // That HACK

 public function renderForm( HTML_QuickForm2 $form ){
  $renderer = HTML_QuickForm2_Renderer::factory( 'default' );

  // Make a new template and drop the date value in..
  // make sure the id to the form handler is the 
  // same as the dateElement added in populateForm 
  // so it is present in the _POST params after submit..
  $renderer->setTemplateForId(
      'dater', '<div class="row"><p class="label"><label 
                                                   style="padding-right:1em;">
                Date: </label></p><br />
                <input id="dater" type="date" name="dater" value="'.$this->_date.
                '" /></div>');

  echo $form->render( $renderer );
 }
}