addElement('text','name', '名前', array('size'=>20, 'maxlength'=>50)); $this->addRule('name', 'お名前を入力して下さい。', 'required'); } // 2 ページめ function buildPage2 (){ $this->addElement('text','age', '年齢', array('size'=>4, 'maxlength'=>3)); $this->addRule('age', '年齢を入力して下さい。', 'required'); } // 3 ページめ function buildPage3 (){ $this->addElement('text','job', '職業', array('size'=>10, 'maxlength'=>13)); $this->addRule('job', '職業を入力して下さい。', 'required'); } } class InputPage1 extends AllPages{ function buildForm(){ $this->_formBuilt = true; $this->addElement('header', null, 'ステップ1'); $this->buildPage1(); $this->addElement('submit', $this->getButtonName('next'), '次へ'); } } class InputPage2 extends AllPages{ function buildForm(){ $this->_formBuilt = true; $this->addElement('header', null, 'ステップ2'); $this->buildPage2(); $submit = array(); $submit[] = $this->createElement('submit', $this->getButtonName('back'), '戻る'); $submit[] = $this->createElement('submit', $this->getButtonName('next'), '確認'); $this->addGroup( $submit, "" ); } } class InputPage3 extends AllPages{ function buildForm(){ $this->_formBuilt = true; $this->addElement('header', null, 'ステップ3'); $this->buildPage3(); $submit = array(); $submit[] = $this->createElement('submit', $this->getButtonName('back'), '戻る'); $submit[] = $this->createElement('submit', $this->getButtonName('next'), '確認'); $this->addGroup( $submit, "" ); } } class ConfirmPage extends AllPages{ function buildForm(){ $this->_formBuilt = true; $this->addElement('header', null, '確認画面'); // なにもしないと 確認画面に表示されない // かといって exportValues の全てを setConstants すると確認画面に来たあと // 戻って編集したデータが更新されていない // よって 必要なページのみのデータを setConstants している。 // もっとよいやり方があったら教えて下さい。 $this->setConstants( $this->controller->exportValues('input1') ); $this->setConstants( $this->controller->exportValues('input2') ); $this->setConstants( $this->controller->exportValues('input3') ); $this->buildPage1(); $this->buildPage2(); $this->buildPage3(); $this->freeze(); $submit = array(); $submit[] = $this->createElement('submit', $this->getButtonName('back'), '戻る'); $submit[] = $this->createElement('submit', $this->getButtonName('next'), '登録'); $this->addGroup( $submit, "" ); } } class ActionProcess extends HTML_QuickForm_Action{ function perform( &$page, $actionName ){ $post = $page->exportValues(); // // ここに登録処理を書く // echo "OK
";
// セッションデータを破棄する必要あり。
print_r( $post );
echo "Back";
}
}
class ActionDisplay extends HTML_QuickForm_Action_Display{
function _renderForm( &$page ){
$rendeerer =& $page->defaultRenderer();
$page->accept( $rendeerer );
$html = $rendeerer->toHtml();
echo "";
echo "{$html}";
}
}
$controller =& new HTML_QuickForm_Controller('Wizard_Test');
$controller->addPage(new InputPage1('input1'));
$controller->addPage(new InputPage2('input2'));
$controller->addPage(new InputPage3('input3'));
$controller->addPage(new ConfirmPage('confirm'));
$controller->addAction('display', new ActionDisplay());
// 次へボタン
$controller->addAction('next', new HTML_QuickForm_Action_Next());
// 戻るボタン
$controller->addAction('back', new HTML_QuickForm_Action_Back());
// ジャンプボタン
//$controller->addAction('jump', new HTML_QuickForm_Action_Jump());
$controller->addAction('process', new ActionProcess());
$controller->run();
?>