0
<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 返回的元素。

它把我逼疯了。

几乎可以告诉我如何将其更改为更有用的日期元素的帖子或手册...

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

浏览器将通过日历和简单的 UI 很好地显示。

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

我要求任何人向我展示他们是如何做到的?

4

1 回答 1

0

哦,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 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 );
 }
}
于 2016-05-18T09:31:11.450 回答