You really should not do this kind of stuff (I mean write plain-text form) if you re using Zend Framework. You should use the built-in methods.
首先,使表格能够形成并形成形式。 然后使用这一非常易懂的代码。 请注意,如果我的工作达到100%,我不会受到审判,但这是你需要的100%逻辑。
Form class
class Application_Form_YourFormName extends Zend_Form
{
public function init()
{
$this->setMethod(self::METHOD_POST);
$this->setAction( THE-URL-WHERE-THIS-FORM-IS-MANAGED );
$Element = new Zend_Form_Element_Text( state );
$Element->setLabel( State: );
$Element->addValidators(array(/*DON T KNOW WHAT KIND OF VALIDATION YOU NEED*/));
$Element->addFilters(array(new Zend_Filter_StringTrim(),
new Zend_Filter_HtmlEntities(array( quotestyle => ENT_QUOTES))));
$Element->setRequired();
$this->addElement($Element);
unset($Element);
$this->addElement( reset , Reset );
$this->addElement( submit , Submit );
}
public function stateNotPresent()
{
$this->removeElement( state );
// Note that getStates() is an hypotetical method of an
// hypotetical Application_Model_State where you can retrieve an
// array containing the list of the state you have. This array is
// needed to fill the Select list.
$States = Application_Model_State::getStates();
$Element = new Zend_Form_Element_Select( statelist );
$Element->setLabel( State: );
$Element->setMultiOptions($States);
$Element->addValidator(new Zend_Validate_InArray($States));
$Element->setRequired();
$Element->setOrder($this->count() - 2);
$this->addElement($Element);
unset($Element);
}
}
<><><><><><>><>><>>>>>>
public function name-of-the-action-you-needAction()
{
$Form = new Application_Form_YourFormName();
if ($this->_request->isPost())
{
if ($Form->isValid($this->_request->getPost()))
{
// Do things. A good text has been entered
}
else
{
$Form->stateNotPresent();
if ($Form->isValid($this->_request->getPost()))
{
// Do things. A good selection has been entered.
}
else
{
// echo the edited form (the one with the dropdown list)
$this->view->Form = $Form;
}
}
}
// The first time the page is requested.
// The page with the text box will be printed
else
$this->view->Form = $Form;
}
VIEW-OF-THE-ACTION.phtml>
if ($this->Form != null)
echo $this->Form;
I hope you ll appreciate the effort I made to let you understand.