Issues with form processing

I am trying to create a form which, depending on the results, sends you to another form for completion. The Form has 3 options marked as 1, 2 and 3 below. The result I want to get is that if:
1 is selected it goes to one webpage 1
if 2 is selected it goes to webpage 2
if 3 is selected it goes to webpage 3
if 1 and 2 are selected it goes to webpage 4
if 1 and 3 are selected it goes to webpage 5
if 2 and 3 are selected it goes to webpage 6
if 1 2 and 3 are selected it goes to webpage 7
and if none are selected it returns an error message.

I have written the code in HTML.

[code]

I would like to report a:


1:

2:

3:


[/code]

Any help would be really appreciated, I am new to PHP and cannot work out how to do the logic on it.

change the form to this

<form name="Reporting" action="form.php" method="post">
    <font size="3"><p><b>I would like to report a:</b></p>
    1: <input type="checkbox" name="rpt_1" value="1"><br>
    2: <input type="checkbox" name="rpt_2" value="2"><br>
    3: <input type="checkbox" name="rpt_3" value="3"><br><br>
    <input type="submit" name="submit">
</form>

Then form.php would be[php]
if($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 is selected, but not 2 or 3
header(“Location: index.php”);
} elseifif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 2 is selected, but not 1 or 3
header(“Location: index.php”);
} elseifif(!$_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 3 is selected, but not 1 or 2
header(“Location: index.php”);
} elseifif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 and 2 are selected, but not 3
header(“Location: index.php”);
} elseifif($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 1 and 3 are selected, but not 2
header(“Location: index.php”);
} elseifif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 2 and 3 are selected, but not 1
header(“Location: index.php”);
} elseifif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// all boxes are selected
header(“Location: index.php”);
} else {
// Nothing has been selected
echo “Nothing selected”;
}[/php]

That should give you a general idea of how to do it.

thanks for that, really helpfull in understanding the logic.

I tried incorporating into my site, but it failed, so I set up a new version to test and still had an error on the first elseifif line (even after creating a gold.php file and changing the location on all lines to this). I then changed elseifif to elseif and instead of an error on the first line I had it on all if and elseif lines.

Any idea why this is happening? The error only states the function is {main}()

granted i may have been wrong in changing to elseif, but i thought i would give it a go.

lol, it was supposed to be elseif. don’t know why i didn’t catch that.

try
[php]
if($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 is selected, but not 2 or 3
header(“Location: index.php”);
} elseif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 2 is selected, but not 1 or 3
header(“Location: index.php”);
} elseif(!$_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 3 is selected, but not 1 or 2
header(“Location: index.php”);
} elseif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 and 2 are selected, but not 3
header(“Location: index.php”);
} elseif($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 1 and 3 are selected, but not 2
header(“Location: index.php”);
} elseif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 2 and 3 are selected, but not 1
header(“Location: index.php”);
} elseif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// all boxes are selected
header(“Location: index.php”);
} else {
// Nothing has been selected
echo “Nothing selected”;
}[/php]

if that doesn’t work, then post what you do have. it could be something with how you the function coded.

no worries, still didnt work. The test version i have is as follows

[code]

Your Title Here

I would like to report a:

1:
2:
3:

[/code]

The form.php is

[php]if($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 is selected, but not 2 or 3
header(“Location: gold.php”);
} elseif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 2 is selected, but not 1 or 3
header(“Location: gold.php”);
} elseif(!$_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 3 is selected, but not 1 or 2
header(“Location: gold.php”);
} elseif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && !$_GET[‘rpt_3’]) {
// box 1 and 2 are selected, but not 3
header(“Location: gold.php”);
} elseif($_GET[‘rpt_1’] && !$_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 1 and 3 are selected, but not 2
header(“Location: gold.php”);
} elseif(!$_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// box 2 and 3 are selected, but not 1
header(“Location: gold.php”);
} elseif($_GET[‘rpt_1’] && $_GET[‘rpt_2’] && $_GET[‘rpt_3’]) {
// all boxes are selected
header(“Location: gold.php”);
} else {
// Nothing has been selected
echo “Nothing selected”;
}[/php]

and gold.php is just a blank document with just the [php]<?php
//and
?>[/php]

Thanks for your help

In the form, change the method to GET, or change all those gets to post. first one is easier though lol :slight_smile:

I have tried it both ways, is easy with replace all lol, and am getting the following:

Notice: Undefined variable: _get in C:\wamp\www\test\form.php on line 3

but on all the lines with “_get” so 3, 6, 9, 12, 15, 18 and it doesn’t correspond to the exclamation marks, so some line have 1 error, some 2 and some 3.

just realised it is cases sensitive, have changed all get to capitals and the issue is now with various" rtp_"'s

ok, well this one took me a while to figure out, so i hope it works.

1 - go back to your original form
2 - assuming you just have 3 checkboxes, this will work (well…it should)
[php]

<?php if($_POST['submit']) { if(!empty($_POST['report'])) { // if NOT empty $report = $_POST['report']; // easier to type lol $ct = count($report); // used so it can properly evaluate each response foreach($report as $rpt) { if($ct == 1 && $rpt == 1 ) { echo "1
"; } elseif($ct == 1 && $rpt == 2) { echo "2
"; } elseif($ct == 1 && $rpt == 3) { echo "3
"; } if($ct == 2 && $rpt != 3) { echo "4
"; exit(); } elseif($ct == 2 && $rpt != 2) { echo "5
"; exit(); } elseif($ct == 2 && $rpt != 1) { echo "6
"; exit(); } if($ct == 3) { echo "7
"; } } } else { echo "Nothing was selected"; } } ?>[/php]

If you don’t use the counter ($ct), it’ll say 1, and 1 and 3 are true, because they are, same with 1 and 2. I put the exits in there to keep it from evaluating past that point, though with the header, it shouldn’t.

I had the echos in there to see where it was in the script, just replace those with the headers.

Sponsor our Newsletter | Privacy Policy | Terms of Service