【问题标题】:show the sucess popup after form submit form?表单提交表单后显示成功弹出窗口?
【发布时间】:2016-09-16 21:35:43
【问题描述】:

在这里,我在 codeigniter 视图页面中添加了一个带有数据模型的表单

<a class="handCursor "  href="javascript:void(0)" id="franchise">Franchisee </a>
<!-- Modal -->
<div class="modal fade" id="franchisee_signup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <form action="<?php echo base_url();?>general/general_form" method="POST" name="signup">
            <div class="modal-header bg-primary">
               <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
               <h4 class="modal-title" id="myModalLabel"><i class="fa fa-desktop"></i> Request For Franchisee Program</h4>
            </div>
            <div style="clear: both;"></div>
            <div class="modal-body clearfix">
               <div class="bk_lft" style="width:100%;">
                  <div class="bk_gr" style="width:100% !important">
                     <div class="contact_form2">
                        <div class="bk_roominfo">
                           <div class="clearfix"></div>
                           <div class="frm_clmn">
                              <label>First Name: <em style="color:#F00;">*</em></label>
                              <input name="first_name" id="txt_name" type="text">
                              <input name="form_type" id="company_name" type="hidden" value="franchise">
                           </div>
                           <div class="frm_clmn1">
                              <label>Last Name: <em style="color:#F00;">*</em></label>
                              <input name="last_name" id="txt_lname" type="text">
                           </div>
                           <div class="frm_clmn">
                              <label>Phone: <em style="color:#F00;">*</em></label>
                              <input name="mobile" id="txt_mobile" type="text">
                           </div>
                           <div class="frm_clmn1">
                              <label>Email: <em style="color:#F00;">*</em></label>
                              <input name="email" id="txt_email" type="text">
                           </div>
                           <div class="frm_clmn1" style="width:100%;">
                              <label>Message:<em style="color:#F00;">*</em></label>
                              <textarea name="message" id="txt_message" cols="" rows="" style="resize:none;"></textarea>
                           </div>
                           <div class="bk_bt" style="float:left; margin-top:12px;">
                              <button type="submit" name="send_contact_enq" id="send_contact_enq" value="Continue" style="float:left;">Send</button>
                           </div>
                        </div>
                     </div>
                     <div class="clearfix"></div>
                  </div>
               </div>
            </div>
         </form>
      </div>
   </div>
</div>

这是表单,我们在控制器中添加插入查询

public function general_form()
{
    $post = $this->input->post();
    unset($post['send_contact_enq']);
    $insert_id = $this->custom_db->insert_record('corporate_form_reqlist',$post);
    redirect(base_url()."general/index");
}

在插入db 的同时提交表单后,我们重定向到首页。我们需要在从控制器重定向之前是否有可能在关闭弹出消息重定向发生后显示成功弹出窗口。

我们尝试了所有我知道但没有得到正确响应的逻辑

【问题讨论】:

  • 使用 flashdata 传递数据。见....codeigniter.com/user_guide/libraries/sessions.html
  • 我也试过了 $this->session->set_flashdata('success_msg', 'Request set to Admin. Admin尽快回复你');但它不会得到
  • 如果您能够在单击确定或关闭按钮时弹出成功消息,只需添加此window.location = "http://www.yoururl.com";
  • 只有弹出消息没有bihola问题
  • 你的意思是重定向页面后需要打开弹窗?

标签: javascript php jquery css codeigniter


【解决方案1】:

尝试将一些值作为参数传递,并通过在重定向页面中检查来给出成功消息..

 redirect(base_url()."general/index?status=success");

和一般/索引文件

 if(isset($_GET['status']) && $_GET['status'] == "success"){
       echo "Successfull Message";
 }

【讨论】:

    【解决方案2】:
    if($insert_id=='success'){//change success based on the returned value of the model
        echo "<script>
            alert('Success');
            window.location.href='".base_url('general/index')."';
            </script>";
    }
    

    【讨论】:

      【解决方案3】:

      您可以为您的表单使用 ajax 函数,该函数将向 PHP 发送数据以执行 general_form 任务而无需重定向。如果成功将记录插入 db 和 javascript,则 PHP 返回 true,然后触发 alert() 或 prompt() 和 windows.location = "your redirection link"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多