简体   繁体   English

单击html表单后使用php提交后弹出

[英]popup after clicking the html form submit using php

I have a submit button"Certificate copy" when i clicked the button it should show a popup. 单击按钮时,我有一个提交按钮“证书副本”,它应该显示一个弹出窗口。 The below one is my html code. 下面的是我的html代码。

print "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>";
print "<form action='details.php' name='copy' method='POST' target='_blank'>";


        print "<input type='hidden' name='certificate_name' value='$certificate_name'>";
        print "<input type='hidden' name='certificate_id' value='$certificate_id'>";


        print "<input type='submit' name='certificatecopy' id='certificate' value='Certificate Copy'>";

print "</form>" ;

and my code for popup is 我的弹出代码是

    print "<script> $(document).on('click','#certificate',function(){val = confirm('Do you want to create a new certificate?');
alert(val);
if(val)
{
     alert('proceed '); 
     return true;
}
else
{
   alert('Dont proceed');
   return false;
}
});</script>";

My problem is, when i click the button at first time the popup box doesn't appear. 我的问题是,当我第一次单击按钮时,弹出框没有出现。 but when the button clicked second time, the popup box is appear. 但是当第二次单击该按钮时,将显示弹出框。 what is the problem. 问题是什么。 I need the popup when the button clicked first time. 第一次单击该按钮时,我需要弹出窗口。 please help. 请帮忙。

You need to do this in client side on button click event . 您需要在客户端单击按钮事件时执行此操作。

Confirm will return the Boolean value true or false . Confirm将返回布尔值true或false。 Based on user click. 基于用户点击。

 $(document).on('click','#certificate',function(){ val = confirm('This will create a new certificate with all properties and links from the original certificate. A certificate user may edit the new certificate properties, but may not delete the certificate. Do you want to create a new certificate?'); alert(val); if(val) { alert('proceed '); return true; } else { alert('Dont proceed'); return false; } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action='details.php' name='copy' method='POST' target='_blank'> <input type='hidden' name='certificate_name' value='$certificate_name'> <input type='hidden' name='certificate_id' value='$certificate_id'> <input type='submit' name='certificatecopy' id="certificate" value='Certificate Copy'> </form> 

Update 1 : 更新1:

<?php
print "<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>";
print "<form action='details.php' name='copy' method='POST' target='_blank'>";


        print "<input type='hidden' name='certificate_name' value='$certificate_name'>";
        print "<input type='hidden' name='certificate_id' value='$certificate_id'>";


        print "<input type='submit' name='certificatecopy' id='certificate' value='Certificate Copy'>";

print "</form>" ;

print "<script> $(document).on('click','#certificate',function(){val = confirm('Do you want to create a new certificate?');
alert(val);
if(val)
{
     alert('proceed '); 
     return true;
}
else
{
   alert('Dont proceed');
   return false;
}
});</script>";

?>

Instead of adding in $_SESSION['pop_up'] just echo it: 无需添加$_SESSION['pop_up']只需echo它即可:

if(isset($_POST['certificatecopy'])){

  echo "<script>
            .....................
            .....................
        </script>";

You want to ask for the confirmation Client side before sending a request to the server? 您要在向服务器发送请求之前要求确认客户端吗?

If you use Bootstrap, you can try a little jQuery plugin I made, https://github.com/delboy1978uk/bs-delete-confirm . 如果您使用Bootstrap,则可以尝试我制作的一个小jQuery插件https://github.com/delboyboyuk/bs-delete-confirm It doesn't need to be used solely for deletion, it's only named that since it's the most used case. 它并不需要仅用于删除,因为它是最常用的情况,所以仅被命名为。

All you do is add a CSS class to your link: 您要做的就是将CSS类添加到链接中:

<a href="/wherever" class="confirm">Do stuff!</a>

And the javascript: 和javascript:

$(document).ready(function(){
  $('.confirm').deleteConfirm();
});

Now when you click the link, the JS intercepts it, launches a bootstrap modal window, and upon confirming, follows your hyperlink. 现在,当您单击链接时,JS会拦截该链接,启动一个引导模式窗口,并在确认后跟随您的超链接。

You can pass options in to the deleteConfirm() method too: 您也可以将选项传递给deleteConfirm()方法:

{
  heading: "Please confirm",
  body: "Are you sure you wish to perform this action?",
  ok_text: "Proceed",
  cancel_text: "Back",
  log: false
}

Hope this helps! 希望这可以帮助! If you don't use Bootstrap, it's well worth addingto your project! 如果您不使用Bootstrap,则值得将其添加到您的项目中! Here's a link to the modal functionality: https://getbootstrap.com/docs/3.3/javascript/#modals 这是模态功能的链接: https : //getbootstrap.com/docs/3.3/javascript/#modals

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM