/ / Jak powinniśmy używać formularza Zend View Helper z walidatorami + filtrami? - zend-framework, zend-form, zend-view

W jaki sposób powinniśmy używać formularza Zend View Helper z walidatorami + filtrami? - zend-framework, zend-form, zend-view

W jaki sposób powinniśmy używać formularza Zend View Helper z walidatorami + filtrami?

Przykład które tracą weryfikatory + filtry od: http://framework.zend.com/manual/en/zend.view.helpers.html

<form action="action.php" method="post">
<p>
<label>Your Email:
<?php echo $this->formText("email", "you@example.com", array("size" => 32)) ?>
</label>
</p>
<p>
<label>Your Country:
<?php echo $this->formSelect("country", "us", null, $this->countries) ?>
</label>
</p>
<p>
<label>Would you like to opt in?
<?php echo $this->formCheckbox("opt_in", "yes", null, array("yes", "no")) ?>
</label>
</p>
</form>

Dzięki,

Odpowiedzi:

0 dla odpowiedzi № 1

Utwórz formularz jako oddzielną klasę, a następnie użyj wszystkich walidatorów i filtrów, które chcesz. W dokumentach są kompletne informacje o konfiguracji:

http://framework.zend.com/manual/en/zend.form.quickstart.html

Przykład z dokumentów:

$form = new Zend_Form();
$form->setAction("/user/login")
->setMethod("post");

// Create and configure username element:
$username = $form->createElement("text", "username");
$username->addValidator("alnum")
->addValidator("regex", false, array("/^[a-z]+/"))
->addValidator("stringLength", false, array(6, 20))
->setRequired(true)
->addFilter("StringToLower");

// Create and configure password element:
$password = $form->createElement("password", "password");
$password->addValidator("StringLength", false, array(6))
->setRequired(true);

// Add elements to form:
$form->addElement($username)
->addElement($password)
// use addElement() as a factory to create "Login" button:
->addElement("submit", "login", array("label" => "Login"));