如何在php中添加确认框

时间:2012-12-31 09:01:08

标签: php

嗨这是我从服务器上删除excel文件的php代码。在这里,我想在删除过程之前添加一个确认框。

<?php
    $files=glob("*.csv");    
    foreach ($files as $list)
    { 
        $file=str_replace(".csv","",$list);?>
            <option value="<?php echo $file;?>"><?php echo $file;?></option>
<?php }?>
     </select>

     <input type="submit" name="download" value="DownLoadExcel">
     <input type="submit" name="delete" value="DeleteExcel">


      <?php

            if (isset($_POST['delete'])=="DeleteExcel")
             {            
                $filename=$_POST['mylist'];
                     if (!empty($filename))
                         {
                             $filename.=".csv";
                             if (file_exists($filename))
                             unlink($filename);
                        }
            }
?>

2 个答案:

答案 0 :(得分:2)

 <input type="submit" name="delete" value="DeleteExcel" onclick="return confirm('Are you sure');">

以这种方式使用

答案 1 :(得分:0)

试试这个,只需在onclick事件中添加javascript确认

<input type="submit" name="delete" value="DeleteExcel" onclick="return confirm('Do you want to delete this?');">