【问题标题】:popup after clicking the html form submit using php单击使用 php 提交的 html 表单后弹出
【发布时间】:2017-08-31 20:08:50
【问题描述】:

当我单击按钮时,我有一个提交按钮“证书副本”,它应该显示一个弹出窗口。 下面是我的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>" ;

我的弹出代码是

    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>";

我的问题是,当我第一次单击按钮时,弹出框没有出现。但是当第二次单击按钮时,会出现弹出框。问题是什么。第一次单击按钮时我需要弹出窗口。请帮忙。

【问题讨论】:

  • 因为 if(isset($_POST['certificatecopy'])){..} 未在 First time page load 上设置。它只会在您单击按钮后设置
  • 您想在客户端执行此操作 - 使用按钮上的单击事件处理程序。
  • 可能与您为此任务使用会话这一事实有关。我猜想您是在尝试显示会话内容后设置的,因此当页面第二次加载时(猜测)。
  • 你需要展示你的完整代码。此代码不会弹出警报
  • 如果有其他方法代替 isset($_POST['certificatecopy']

标签: javascript php html popup


【解决方案1】:

而不是添加 $_SESSION['pop_up'] 只是 echo 它:

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

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

【讨论】:

  • 我需要弹出框,因为一旦他们点击确认,我将执行另一个功能
  • JyoThl 解决方案应该可以工作
【解决方案2】:

您需要在客户端的按钮单击事件中执行此操作。

Confirm 将返回布尔值 true 或 false 。基于用户点击。

$(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>

更新 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>";

?>

【讨论】:

  • 以上示例用于警报消息。我必须创建确认框。
  • 不,这是确认框@SoundaryaE 看看我的js代码。
  • 试试上面的 sn-p 。点击按钮Run code Snippet@SoundaryaE
  • 是的,它正在工作。但在我的应用程序中,弹出窗口没有出现
  • 可以使用编辑按钮@SoundaryaE 使用更新的代码发布您的帖子
【解决方案3】:

您想在向服务器发送请求之前要求客户端确认吗?

如果你使用 Bootstrap,你可以试试我做的一个小 jQuery 插件,https://github.com/delboy1978uk/bs-delete-confirm。它不需要单独用于删除,它只是命名,因为它是最常用的情况。

您只需在链接中添加一个 CSS 类:

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

还有 javascript:

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

现在,当您单击链接时,JS 会拦截它,启动引导模式窗口,并在确认后跟随您的超链接。

您也可以将选项传递给 deleteConfirm() 方法:

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

希望这会有所帮助!如果您不使用 Bootstrap,那么值得添加到您的项目中!这是模态功能的链接: https://getbootstrap.com/docs/3.3/javascript/#modals

【讨论】:

  • 我是新手。如果我在我的代码中添加 ajax,那么任何东西都会添加到我的 php 代码中,比如库
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多