我有一個關於在twitter引導模式中使用zend表單的問題。這是我有:Zend Form in Modal - 提交表格
在我的控制器:
public function accountAction() {
$form = new Form_CancelAccount();
$this->view->form = $form;
// Some executions and view params for the view, ex:
/*if ($user->getRecurlyId() && NameSpace_Feature_Access_RoleHelper::hasAccess('show_billing')) {
try {
$account = Recurly_Account::get($user->getRecurlyId());
$this->view->token = $account->hosted_login_token;
$this->view->show_billing = true;
} catch (Recurly_NotFoundError $e) {
$this->view->show_billing = false;
}
} else {
$this->view->show_billing = false;
}*/
if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
$data = $form->getValues();
var_dump($data);
} else {
var_dump("it didn't work!");
}
}
我CancelAccount形式:
<?php
class Form_CancelAccount extends NameSpace_Form_Base
{
public function __construct($options = null) {
parent::__construct($options);
$this->setName('cancelaccount');
$element = new Zend_Form_Element_Radio('reason');
$element->addMultiOptions(array(
'It is really bad!' => 'bad',
'No time for it!' => 'notime',
'Other option:' => 'otheroption'
))->setDecorators(array(array('ViewScript', array('viewScript' => 'user/radio.phtml'))));
$this->addElement($element);
$this->addElement('text', 'otheroption', array(
'attribs' => array(
'class' => 'input-block-level otheroption',
'size' => 30,
'placeholder' => 'Other option'
),
'decorators' => $this->elementDecoratorsNoTag
));
}
}
在我看來:
// Some data sent from the controller
<h4>Delete account</h4>
<p>Deleting of your account implies your account and the related data will be deleted. Please note that this is not reversible.</p>
<button type="button" data-target="#cancelModal" data-toggle="modal" class="btn btn-primary">Delete account</button>
<div class="modal hide fade" id="cancelModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<?php echo $this->form; ?>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-default" value="OK" form="cancelaccount">
<a id="cancel" class="btn btn-default close" data-dismiss="modal">Cancel</a>
</div>
但我始終得到輸出'it didn't work!'
來自var_dump當窗體無效...。什麼是最好的方法來做到這一點?它是如何發生的,它總是無效的?
UPDATE:
當我離開了"&& $form->isValid($_POST)"
在我的if語句我進來的語句,但我的var_dump表明這一點:
陣列(大小= 2)
'理由'= >空
'otheroption'=>空
我的響應:
問題是我的單選按鈕無效......我該如何解決這個問題?
你確定窗體使用'POST'方法嗎? – Mina
是的,當我離開「&& $ form-> isValid($ _ POST)」時,如果我收到迴應。只有字段是空的..(更新開始發佈) – nielsv