form branching question
Posted: Sun May 20, 2007 1:58 pm
Hi guys,
This code below shows a form, and allows you to adjust the number of rocks you're entering, then returns to PHP_SELF so you can enter rocks.
When done, I hit the SEARCH button, which I'd like to pass values to a different page. [not shown] Unfortunately, it's not quite what I wanted...
Of course, a viewer needs to hit the SEARCH button twice... I'm trying to think of a different way to exit the form and pass values to a different page. Any ideas?
Cut
This code below shows a form, and allows you to adjust the number of rocks you're entering, then returns to PHP_SELF so you can enter rocks.
When done, I hit the SEARCH button, which I'd like to pass values to a different page. [not shown] Unfortunately, it's not quite what I wanted...
Code: Select all
<?
session_start();
?>
<?
if(!isset($_SESSION['count'])) {
$_SESSION['count'] = 4;
$formaction=$_SERVER['PHP_SELF'];
}
if(isset($_SESSION['count']) && isset($_POST['ADD'])) {
$_SESSION['count']++;
$formaction = $_SERVER[’PHP_SELF’];
}
if(isset($_SESSION['count']) && isset($_POST['REMOVE'])) {
$_SESSION['count']--;
$formaction=$_SERVER[’PHP_SELF’];
}
if(isset($_POST['SEARCH'])) {
$formaction="/results.php";
}
$count = $_SESSION['count'];
echo "<form id = \"form\" method=\"POST\" action=$formaction>";
for ($i = 0; $i < $count; $i++) {
echo "<p>";
echo "Rock: <input type=\"text\" name=\"rock[]\" />";
echo "Amount: <input type=\"text\" name=\"amount[]\" />";
echo "Amount Type: <input type=\"text\" name=\"amounttype[]\" />";
echo "</p>";
}
echo "<input type=\"submit\" value = \"Add another rock\"
name=\"ADD\" />";
echo "<input type=\"submit\" value = \"Remove a rock\"
name=\"REMOVE\" />";
echo "<input type=\"submit\" value = \"Search\"
name=\"SEARCH\" />";
?>Of course, a viewer needs to hit the SEARCH button twice... I'm trying to think of a different way to exit the form and pass values to a different page. Any ideas?
Cut