哦,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 );
}
}