0

I am looking for help about a basic problem. I would like to write a .php script, what generates a HTML form, and when the form is submited, then the same .php script gets the form paramter, do the operation.

This is code I have so far, but it is not working:

<?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];

?>

My goal is put a separate html file and a php file together, where the php file is generating the html form, and the same php script interpreters it.

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;

?>
Tass Mark
  • 337
  • 1
  • 2
  • 14
  • Well, I have more than 5.000 lines of code already, to do that task ... create form, prefill form, validate form, prepare data from database (or other) for form values/labels/options, sanitize input and do security/white listing checks ... forgot something? ... form templating, preparing sql for saving back the posted information. – djot Sep 09 '13 at 11:18
  • 1
    "it is not working" is *not* a problem description. Also yay! XSS vulnerability \o/ – PeeHaa Sep 09 '13 at 11:18

1 Answers1

1

For a start Change

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

to

echo "<form name='input' action='phptest1.php' method='post'>";
allen213
  • 2,267
  • 2
  • 15
  • 21
  • Hello, allen213, thank you, I fixed it. My goal is put a separate html file and a php file together, where the php file is generating the html form, and the same php script interpreters it. a1.html:
    Type the folder name:
    a2.php
    – Tass Mark Sep 09 '13 at 14:54