So basically what I'm doing is generating a simple form to take in a number. Based on this number I'm producing an equal normal of text inputs with a new submit button associated for these input forms. The problem is I need to keep up with the original number of forms to pass as an index value to an array that I want to store the values from the new set of text inputs. But when I submit the new form, the value keeps dropping. Here is my code below.
Note: I've commented out the algorithm I'm attempting to store the values from the text inputs and just attempting to echo the value number of forms and not having this value is preventing me from entering my for loop where I'd like to store the values.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Kid Order Selector</title>
</head>
<body>
<form action="kid_selector.php" method="post">
Enter number of kids playing:<input type="text" name="num_kids" /><input type="submit" name="submit" value="Submit" />
</form>
<br /><br />
<form action="kid_selector.php" method="post">
<?php
if(isset($_POST["num_kids"])) {
$num_kids = $_POST["num_kids"];
echo "Enter the following kids names:<br />";
for($i = 1; $i <= $num_kids; $i++) {
echo "<input type=\"text\" name=\"kid{$i}\" /><br />";
$index = $i;
}
if( $num_kids == $index ) {
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\" />";
}
$numkids = $num_kids;
} else {
$num_kids = "";
}
?>
<?php
//$kids = array();
echo $numkids;
if(isset($_POST["kid1"])) {
echo "Success";
for($i=0; $i < $numkids; $i++) {
// $index = $i + 1;
//$pos = "kid{$index}";
//echo $pos;
//$kids[$i] = $_POST[$pos];
echo "Success";
}
//print_r($kids);
}
?>
</form>
</body>
</html>