在警告弹出脚本函数php中运行函数

时间:2012-12-20 08:05:23

标签: php encryption dialog popup dropbox

我有加密方法&上传方法,点击加密按钮后,我想有一个弹出对话框,说明我是否要在加密后上传到Dropbox,对话框由yes或no组成。如果不是,我只想加密文件,如果是,我希望文件加密并上传到保管箱。

目前我的方法是分开的,我想通过使用弹出按钮将它们连接在一起。

谢谢!

这是弹出脚本功能:

<script>
function confirmDelete(delUrl) {
  if (confirm("Do you want to upload to Dropbox?")) {
   document.location = delUrl;
  }
}

</script>

<a href="javascript:confirmDelete('delete.page?id=1')">Encrypt</a>

如果单击是,如何在弹出脚本中运行此功能?

加密表单

<form>
<b>Select file to encrypt:</b>
<br>
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<br>
<input type="submit" value=" Encrypt ">

</form>  

上传表单

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<b>Select file to upload:</b>
<br>
<label for="file">Filename:</label>
<input type="file" name="path" id="file"><br>
<input type="submit" name="submit" value=" Upload ">

</form>

2 个答案:

答案 0 :(得分:0)

您需要在表单中添加隐藏的输入以区分表单提交类型 在表单中添加onsubmit处理程序,然后在提交时检查$_POST['action_type']

<script type="text/javascript">
function confirmUpload() {
  if (confirm("Do you want to upload to Dropbox?")) { // click 'Yes'
    document.getElementById('action_type').value = 'upload'
  }else{ // click 'No'
    document.getElementById('action_type').value = 'encrypt'
  }
  return true;
}
</script>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" onsubmit="return confirmUpload()">
    <b>Select file to upload or encypt:</b>
    <br>
    <label for="file">Filename:</label>
    <input type="file" name="path" id="file"><br>
    <input type="submit" name="submit" value=" Upload or Encrypt" >
    <input type="hidden" id="action_type" name="action_type" value="" />
</form>

答案 1 :(得分:0)

    <script>
    function confirmDelete(delUrl) {
      confirm="Do you want to upload to Dropbox?"
if(confirm) {
       document.location = delUrl;
      }
    }

    </script>


    <a href="javascript:: void(0);" onclick="return confirmDelete('delete.page?id=1');>Encrypt</a>

这可能有用。

相关问题