[Zend Framework] Zend_Form: Zend_Form を使わない form

別件調査の副産物。

[markdown]

Zend_Formを使った方がメリットがありそう。

Zend_Form 2013-07-13 08-52-00

“`php:application/views/scripts/index/about.phtml

foo(必須チェック。小文字に変換。)
bar(日付形式チェック。)

“`

“`php:application/controllers/IndexController.php
public function aboutAction()
{
// action body
$errors = ”;
if ($this->getRequest()->isPost()) {
$text = $this->getRequest()->getParam(‘text’);
$date = $this->getRequest()->getParam(‘date’);
$text = Zend_Filter::filterStatic($text, ‘StringToLower’);
if (! Zend_Validate::is($text, ‘NotEmpty’)) {
$errors .= ”

  • fooは、入力が必要です。
  • “;
    }
    if (! Zend_Validate::is($date, ‘Date’)) {
    $errors .= ”

  • barは、正しい日付の形式ではありません
  • “;
    }
    }
    if ($errors == ”) {
    $data = array(
    ‘text’ => $text,
    ‘date’ => $date
    );
    Zend_Debug::dump($data);
    }
    $this->view->assign(‘errors’, $errors);
    }
    “`

    [/markdown]