[英]ZF2-Form submission without reloading the page in the modal itself as shown in picture
我想提交此表单而不重新加载页面(在模态本身内部)。验证表单后,它应该重定向到所需的页面,而不是在表单发布之后。 注意: 我不想使用AJAX谢谢。 这是图片:
这是我尝试过的
public function listAction()
{
if(!$user = $this->identity())
return $this->redirect()->toRoute('user',array('action'=>'login'));
$em = $this->getEntityManager();
$survey = new Survey();
$form = new SurveyForm();
$message="Create Survey";
$surveyList = $em->getRepository('Easysurvey\Entity\Survey')->findall();
$form->get('submit')->setValue('Save & Add Question');
$form->setHydrator(new DoctrineHydrator($em,'Easysurvey\Entity\Survey'));
$form->bind($survey);
//add new
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
$form->setInputFilter(new SurveyFilter($this->getServiceLocator()));
$form->setData($data);
if ($form->isValid()) {
$this->prepareData($survey);
$this->flashMessenger()->addSuccessMessage('succesfully created');
$em->persist($survey);
$em->flush();
return $this->redirect()->toRoute('survey', array('action' => 'list'));
}
}
}
return array('form' => $form,
'surveyList' => $surveyList,
'message' => $message
);
}
list.phtml:
<!-- Create Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel"><?php echo $message?></h4>
</div>
<div class="modal-body">
<?php
$form->setAttribute('action', $this->url('survey', array('action' => 'list')),'class','form-horizontal');
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('name'));
echo '<br />';
echo $this->formRow($form->get('description'));
echo '<br />';
echo $this->formRow($form->get('startdate'));
echo '<br />';
echo $this->formRow($form->get('enddate'));
echo '<br />';
echo $this->formRow($form->get('createdby'));
echo '<br />';
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close </button>
</div>
</div>
</div>
为此,您需要使用JavaScript,Jquery使ajax调用非常简单,基本上是:
获取URL:$('form.form-horizontal')。attr('action');
然后,在执行请求后调用的回调中,隐藏引导程序模式,并有选择地向最终用户显示成功消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.