954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Utter newbie & stressing redirect based on form value

Dear All

I have made a successful html form with mail.php "thing" my only problem is I want to be able to redirect to 2 different thank you pages based on a value entered in the html form.

Value field is "Type1" and people can enter either burger, farm or shop

Thank you.....

this is my mail.php

<?php
$name = $_POST['name'];
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$adres = $_POST['adres'];
$plaats = $_POST['plaats'];
$postcode = $_POST['postcode'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$socialemedia = $_POST['socialemedia'];
$website = $_POST['website'];
$Type1 = $_POST['Type1'];
$type = $_POST['type'];
$productendiensten = $_POST['productendiensten'];
$productendiensten_anders = $_POST['productendiensten_anders'];
$vragen = $_POST['vragen'];
$formcontent=" Bevestiging van: $name, deze persoon is $Type1 \n Bedrijfsnaam: $bedrijfsnaam \n Adres: $adres $postcode $plaats \n Gebruiker van Sociale Media: $socialemedia \n Producten en Diensten: $productendiensten \n Anders: $productendiensten_anders \n Vragen en/off Opmerkingen: $vragen";
$recipient = "me@myemail.com";
$subject = "Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if (isset ($Type1['Burger']))
{
header("Location: burgerthanks.htm"); //the user will be sent to this page
}
if (isset ($Type1['Farm'])) {
header('Location: option2.htm');
} else
header('Location: thanks1.htm');
?>

LegoBeast
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

you must exit after using header function

<?php
$name = $_POST['name'];
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$adres = $_POST['adres'];
$plaats = $_POST['plaats'];
$postcode = $_POST['postcode'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$socialemedia = $_POST['socialemedia'];
$website = $_POST['website'];
$Type1 = $_POST['Type1'];
$type = $_POST['type'];
$productendiensten = $_POST['productendiensten'];
$productendiensten_anders = $_POST['productendiensten_anders'];
$vragen = $_POST['vragen'];
$formcontent=" Bevestiging van: $name, deze persoon is $Type1 \n Bedrijfsnaam: $bedrijfsnaam \n Adres: $adres $postcode $plaats \n Gebruiker van Sociale Media: $socialemedia \n Producten en Diensten: $productendiensten \n Anders: $productendiensten_anders \n Vragen en/off Opmerkingen: $vragen";
$recipient = "me@myemail.com";
$subject = "Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if (isset ($Type1['Burger']))
{
header("Location: burgerthanks.htm"); //the user will be sent to this page
exit;
}
if (isset ($Type1['Farm'])) {
header('Location: option2.htm');
exit;
} else
header('Location: thanks1.htm');
exit;
?>
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

I tried this but it keep defaulting to the first header burgerthanks.htm regardless of people enter ;(. It seems it does not want to go through with the other steps...

LegoBeast
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

isset check whether the variable exists or not , it returns true even if the value is blank. so you may check accordingly like

if (isset ($Type1['Burger']) && trim($Type1['Burger'])!='' ) {
{
header("Location: burgerthanks.htm"); //the user will be sent to this page
exit;
}
if (isset ($Type1['Farm']) && trim($Type1['Farm'])!='' ) {
header('Location: option2.htm');
exit;
} else
header('Location: thanks1.htm');
exit;
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

hi urtrivedi nope still not working... SORRY!!! I now if I copy and paste the full lot also get an error message

<?php
$name = $_POST['name'];
$bedrijfsnaam = $_POST['bedrijfsnaam'];
$adres = $_POST['adres'];
$plaats = $_POST['plaats'];
$postcode = $_POST['postcode'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$socialemedia = $_POST['socialemedia'];
$website = $_POST['website'];
$Type1 = $_POST['Type1'];
$type = $_POST['type'];
$productendiensten = $_POST['productendiensten'];
$productendiensten_anders = $_POST['productendiensten_anders'];
$vragen = $_POST['vragen'];
$formcontent=" Bevestiging van: $name, deze persoon is $Type1 \n Bedrijfsnaam: $bedrijfsnaam \n Adres: $adres $postcode $plaats \n Gebruiker van Sociale Media: $Twitter, $Facebook, $LinkedIn, $Hyves \n Producten en Diensten: $productendiensten \n Anders: $productendiensten_anders \n Vragen en/off Opmerkingen: $vragen";
$recipient = "me@myemail.com";
$subject = "Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
if (isset ($Type1['Burger']) && trim($Type1['Burger'])!='' ) {
{
header("Location: burgerthanks.htm"); //the user will be sent to this page
exit;
}
if (isset ($Type1['Farm']) && trim($Type1['Farm'])!='' ) {
header('Location: option2.htm');
exit;
} else
header('Location: thanks1.htm');
exit;
?>

on the last line...

the html form with the value bit

Ik ben een ....
BurgerFarmSausage

LegoBeast
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 
if (trim($Type1)=='Burger' ) {
{
header("Location: burgerthanks.htm"); //the user will be sent to this page
exit;
}
if (trim($Type1)=='Farm']) {
header('Location: option2.htm');
exit;
} else
header('Location: thanks1.htm');
exit;
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: