dongtao4319 2014-10-07 05:48
浏览 21
已采纳

ZF2-Form提交没有在模态本身重新加载页面,如图所示

I want to submit this form without reloading the page (inside the modal itself).After validating form it should redirect to the desired page not after form posting. note:I do not want to use AJAX thank you. Here is the Image:enter image description here

here is what i have tried..

     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">&times;</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>
  • 写回答

1条回答 默认 最新

  • donglei1616 2014-10-07 09:37
    关注

    You need javascript for that, Jquery make ajax calls really simple, basically:

    To get the url: $('form.form-horizontal').attr('action');

    Then on the callback which is a function called after the request is executed, you hide the bootstrap modal and optionally show a success message to the end user.

    $.ajax()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab