0

我正在寻求有关基本问题的帮助。我想写一个 .php 脚本,生成一个 HTML 表单,提交表单后,同样的 .php 脚本获取表单参数,进行操作。

这是我到目前为止的代码,但它不起作用:

<?php 

echo "<html>";
echo "<head>";
echo "<title>This is a test</title>";
echo "</head>";
echo "<body>";
echo "<form name='input' action='phptest1.php' method='get'>";
echo "Type the folder name: <input type='text' name='foldername[]'>";
echo "<input type='submit' value='OK'>";
echo "</form>";
echo "</form>";
echo "</body>";

$folder_var = $_POST['foldername'];
  if(empty($folder_var)) 
  {
    echo("No folder name was specified.");
    exit();
  } 
      echo "Folder name is : " . $folder_var[0];

?>

我的目标是将一个单独的 html 文件和一个 php 文件放在一起,其中 php 文件生成 html 表单,并且相同的 php 脚本解释它。

a1.html:

<html>
<head>
<title>This is a test</title>
</head>
<body>
<form name="input" action="a2.php" method="post">
Type the folder name: <input type="text" name="foldername">
<input type="submit" value="OK">
</form>

</body>

a2.php

<?php 


$folder_var = $_POST['foldername'];
  if(empty($folder_var)) 
  {
    echo("No folder name was specified.");
        exit();
  } 
      echo "Folder name is : " . $folder_var;

?>
4

1 回答 1

1

开始改变

echo "<form name='input' action='phptest1.php' method='get'>";

echo "<form name='input' action='phptest1.php' method='post'>";
于 2013-09-09T11:20:53.927 回答