【问题标题】:Run function in alert popup script function php在警报弹出脚本函数php中运行函数
【发布时间】:2012-12-20 08:05:22
【问题描述】:

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

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

谢谢!

这是弹出脚本函数:

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

【问题讨论】:

    标签: php encryption dialog popup dropbox


    【解决方案1】:
        <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>
    

    这可能行得通。

    【讨论】:

      【解决方案2】:

      您需要在表单中添加隐藏输入以区分表单提交类型。
      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>
      

      【讨论】:

      • 确实上传成功,但是没有加密。我尝试在此行之后添加加密过程 if (confirm("Do you want to upload to Dropbox?")) { // click 'Yes' document.getElementById('action_type').value = 'upload' 但还是这样不起作用。
      • @SarahPhil,动作类型upload表示上传和加密。如果upload,则需要调用加密过程。
      猜你喜欢
      • 1970-01-01
      • 2011-07-29
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 2015-05-10
      相关资源
      最近更新 更多