你能领导这样的事情。您必须确定要如何处理表单。如果通过 Ajax - 下面的示例。
<?php
class TestController
extends Zend_Controller_Action
{
function indexAction() {
}
// render form
function getFormAction() {
$form = new Zend_Form();
$form->addElement('hidden', 'isSubmit', array(
'value' => 1
));
$form->addElement('text','foo', array(
'required' => true
));
$form->addElement('submit','Send', array(
'label' => 'ok'
));
// $data
if( $_POST['isSubmit'] && $form->isValid($_POST)) {
// ...............
}
if( $this->_request->isXmlHttpRequest() ) {
// render only ajax content in layout-content.phtml
$this->_helper->layout->setLayout('layout-content');
} else {
// render full page elements
$this->_helper->layout->setLayout('layout-default');
}
$this->view->form = $form;
}
}
模板:
<!-- index.phtml -->
<div id="form-wrapper"></div>
<script type="text/javascript">
<!--
$(function() {
$("#form-wrapper").load( "<?= $this->url( array('action'=>'get-form') ) ?>");
});
//-->
</script>
<!-- index.phtml -->
和
<!-- get-form.phtml -->
<?php
if( $this->form ) {
$this->form->setAttrib('id', 'my-form');
$this->form->setAction( $this->url() );
echo $this->form;
}
?>
<script type="text/javascript">
<!--
$(function() {
$('#my-form').submit( function() {
var f = $(this);
$.post(
f.attr('action'),
f.serialize(),
function(data) {
$('#form-wrapper').html(data);
}
);
return false;
});
});
//-->
</script>
<!-- /get-form.phtml -->
迎接帕韦拉