2016-05-18 4 views
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から返された要素に精通していると思います。HTML_QuickForm2日付要素のテンプレート

それは私を夢中にさせた。 ...どのように多くの便利な日付要素に変更するブラウザがカレンダーと簡単なUIで非常にうまく表示していました

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

を私に言うことができる

近付いポストやマニュアル。

私は、彼らはそれをやったどのように私を示すために、誰に頼む...

を、私は、テンプレートの再定義が順番にあった考え出したので、私は、私はそれをやったか、次を紹介します??

答えて

0

ああQuickForms、You Beauty。

$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); 
} 
} 
関連する問題