1

I just made a basic form page and through Aptana, WAMP, and through a basic 1and1 hosted page, I cannot get the form fields to pass through the $_POST superglobal.

Here is the index.html page:

<html>
<head>
    </head>
    <body>
        <p>Type in the areas</p>
    <form action="keywords.php" method="POST">
        <label for="Area1"> 1:</label>
        <input type="text" id="Area1" name="first area /"><br />
        <label for="Area1"> 2:</label>
        <input type="text" id="Area2" name="second area /"><br />
        <label for="Area1"> 3:</label>
        <input type="text" id="Area3" name="third area /"><br />
        <label for="Area1"> 4:</label>
        <input type="text" id="Area4" name="fourth area /"><br />
        <label for="Area1"> 5:</label>
        <input type="text" id="Area5" name="fifth area /"><br />
        <label for="Area1"> 6:</label>
        <input type="text" id="Area6" name="sixth area /"><br />
        <label for="Area1"> 7:</label>
        <input type="text" id="Area7" name="seventh area /"><br />
        <label for="Area1"> 8:</label>
        <input type="text" id="Area8" name="eighth area /"><br />
            <input type="submit" value="Run" name="Run">
            </form>
    </body>
</html>
?>

Which passes to keywords.php

<?php

 if(isset($_POST['submit'])){
     echo "test";


    $area1 = $_POST['Area1'];
    $area2 = $_POST['Area2'];
    $area3 = $_POST['Area3'];
    $area4 = $_POST['Area4'];
    $area5 = $_POST['Area5'];
    $area6 = $_POST['Area6'];
    $area7 = $_POST['Area7'];
    $area8 = $_POST['Area8'];


    echo $area1;
 }
 ?>

Dear lord what am I doing wrong. Be gentle. PHP 5.3.4

Damian Yerrick
  • 4,602
  • 2
  • 26
  • 64
Jack Reed
  • 11
  • 1

3 Answers3

2

The variables are inserted into $_POST based on the name. So it would be $_POST['first area'].

Also, I don't know if it is bad copying, but there should be no slashes inside the name...they should be outside the quotes. For instance:

<input type="text" id="Area1" name="first area" /><br />
Thomas
  • 4,889
  • 4
  • 24
  • 19
2

Err, in your PHP code you're referring to the value you've given in the HTML id attribute, not the name attribute of the form elements. The browser passes the name attribute as the name of the form element. Try $_POST['first area'], etc. :)

Jeremy
  • 2,651
  • 1
  • 21
  • 28
1

You can actually pass all the inputs as one array.

Here's an example.

<html>
<head>
    </head>
    <body>
        <p>Type in the areas</p>
    <form action="keywords.php" method="POST">
        <label for="Area1"> 1:</label>
        <input type="text" id="Area1" name="area[]"><br />
        <label for="Area1"> 2:</label>
        <input type="text" id="Area2" name="area[]"><br />
        <label for="Area1"> 3:</label>
        <input type="text" id="Area3" name="area[]"><br />
        <label for="Area1"> 4:</label>
        <input type="text" id="Area4" name="area[]"><br />
        <label for="Area1"> 5:</label>
        <input type="text" id="Area5" name="area[]"><br />
        <label for="Area1"> 6:</label>
        <input type="text" id="Area6" name="area[]"><br />
        <label for="Area1"> 7:</label>
        <input type="text" id="Area7" name="area[]"><br />
        <label for="Area1"> 8:</label>
        <input type="text" id="Area8" name="area[]"><br />
            <input type="submit" value="Run" name="Run">
            </form>
    </body>
</html>

Would get you one variable: $_POST['area'] This variable is an 8-value array you can then iterate.

Stephen Walcher
  • 2,565
  • 1
  • 21
  • 22