Forum Moderators: coopster
I'm having a problem getting the contents of this $_Post index into my trigger variable. Here's the snippet:
if (isset($_POST['submit'])) {
$buttonHit = $_POST['name'];
} else {
$buttonHit = "step1";
}
The input button on this page looks like this:
<input type="submit" name="step2" value="Make Reservation" />
So... when I hit this button, "step2" should be loaded into $buttonHit, but it isn't - only the default choice of "step1". Hummm.
I've done a lot of Googling for the error of my ways, but ever example I see is the same as the syntax that I've written above.
Where am I going wrong?
Neophyte
<input type="hidden" name="name" value="step2" />
Or you could use radio buttons:
<input type="radio" name="name" value="step1" />
<input type="radio" name="name" value="step2" />
Basically, you need an input element of some sort which has a name="name" somewhere -- the value (what's the $_POST variable actually contains) is sent in value="whatever".
In that case you could do the following:
<input type="submit" name="reservation" value="Make Reservation">
<input type="submit" name="information" value="Get Information">
if ($_POST['reservation'])) {
$buttonHit = "reservation";
}
if ($_POST['information'])) {
$buttonHit = "information";
}
Only one of the two variables will exist depending on which button was clicked.
phpmaven - you've given me the closest solution to what I'm trying to do; appreciate that.
What I'm really trying to do is to streamline what I've found works in this snippet:
foreach($_POST as $key => $value){
$arr = explode("_", $key);
$buttonHit=$arr[0];
$rowId=$arr[1];
}
I use the above when I have multiple submit buttons on a single page (as you mentioned) which works like a charm.
In the above, I name my submits name="edit_1" for example. "edit" being the buttonhit and "1" being the db table row that will be affected. Works great.
What I'm trying to do NOW is use button name values, (without using the explode) in order in order to detect what button has been hit in order to determine what content to "include", like this:
<?php
if (isset($_POST['submit'])) {
$buttonHit = $_POST['name'];
} else {
$buttonHit = "step1";
}
?>
<?php
include('_includes/header.inc.php');
switch ($buttonHit){
case "step1":
// include the first reservation page.
include('_includes/step1.inc.php');
break;
case "step2":
include ('_includes/step2.inc.php');
break;
case "step3":
// include the detail verification page
include ('_includes/step3.inc.php');
break;
}
case "step4":
// include the "Reservation Competed" page
include ('_includes/step4.inc.php');
break;
}
include('_includes/footer.inc.php');
?>
So, I'm just trying to get the value of whatever "name" is set to.
if an input button's name is defined as "continue" <name="continue"> I don't understand what I'm not doing to simply get the name of the button as I can by using explode.
Any further guideance would be great; failing that I'll just use the stacked "ifs" as suggested.
Neophyte