本文介绍了在显示代码之前,php显示警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一点帮助我的PHP代码

i need a little help with my php code

这里是我的整个代码

<!doctype html>
<html>
<head>
   <meta charset="utf-8">
   <title>Untitled Document</title>
</head>

<body>

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    if(empty($_POST['filename']))
    {
       $schanName[] = 'File Name is Required';
    }

    if($_POST['thisfolder'] == 'default')
    {
       $schanName[] = 'Please select a Folder';
    }

    $filename=$_POST['filename'];
    $words = array("1", "2", "3", "4", "5");
    $arrlength = count($words);
    $found = false;

    for($x = 0; $x < $arrlength; $x++)
    {
       if($filename == $words[$x])
       {
          $found = true;
       }
    }

    if($found)
    {
       $schanName[] = 'Not a valid File Name';
    }

    // the name of the file to create
    $filename=$_POST['filename'];
    // the name of the file to be in page created
    $strin=$_POST['strin'];
    // the name of the file to be in page created
    $strin2=$_POST['strin2'];
    // the name of the folder to put $filename in
    $thisFolder = $_POST['thisfolder'];
    // make sure #thisFolder of actually a folder
    if (!is_dir(__DIR__.'/'.$thisFolder))
    {
        // if not, we need to make a new folder
        mkdir(__DIR__.'/'.$thisFolder);
    }
    // . . . /[folder name]/page[file name].php
    $myFile = __DIR__.'/'.$thisFolder. "/page" .$filename.".php";

    // This is another way of writing an if statment
    $div = ($strin !== '') ? '<div id="area_code">'.$strin.'</div>' : '<div   id="area_code">'.$strin2.'</div>';

   $fh = fopen($myFile, 'w');
   $stringData = "";

   fwrite($fh, $stringData);
   fclose($fh);
}

?>


<?php
  // display your errors here
  if(!empty($schanName))
  {
     foreach ($schanName as $sn)
     {
        echo '<div id="error"><ul><li>'.$sn.'</li></ul></div>';
     }
  }
?>


<form class="s_submit" method="post">
<label class="def_lab">File:</label>
<input class="t_box" type='text' name='filename' placeholder='File Name'>
<label class="t_lab def_lab">Select Folder:</label>
<select id="soflow" name="thisfolder">
    <option selected="selected" value="default">Default</option>
    <option value="../embed/tv/xbox/">Xbox</option>
    <option value="Folder2">Folder2</option>
    <option value="Folder3">Folder3</option>
</select><br><br>
<label class="def_lab">Text Area 1:</label><br>
<textarea class="tarea_box" type='text' name='strin'></textarea><br><br>
<label class="def_lab">Text Area 2:</label><br>
<textarea class="tarea_box" type='text' name='strin2'></textarea><br>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

</body>
</html>

我在这里尝试做的是,当我点击提交按钮时,它必须显示是和没有选择。如果我点击YES然后它必须执行代码,如果我点击否则不执行任何操作。希望你明白

what i am trying to do here is , when i clicked o submit button it must show me YES and NO options. if i clicked on YES then it must excute the code and if i clicked NO then do nothing. hope you get it

推荐答案

试试这个我用javascipt confirm函数添加yes或no。并且document.forms [0] .submit()用于提交您的第一个表单。

Try this I have used javascipt confirm function to add a yes or no. And document.forms[0].submit() for submission of your first form.

function show_alert() {
      if(confirm("Do you really want to do this?"))
        document.forms[0].submit();
      else
        return false;
    }

  <button type="submit" class="btn btn-primary" onclick="show_alert()">Submit</button>

这篇关于在显示代码之前,php显示警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:52
查看更多