0

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

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

谢谢!

这是弹出脚本功能:

<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>
4

2 回答 2

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>
于 2012-12-20T08:14:11.517 回答
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>

这可能有效。

于 2012-12-20T08:14:59.277 回答