Page 1 of 1

[Solved]switch not working

Posted: Wed Feb 21, 2007 1:49 am
by Gimpy
Okay sports fans, here is another treat for you problem solving junkies.
I have site that is using some switches so I can save time (later)

Okay so the submit.php has the switch

submit.php

Code: Select all

switch ($form) {
	case "email":
	include "thanks.php";
	default:
	include "comm_form.php";
	break;
	}
The actual file that does the emailing for a request to be added to the site is this.

comm_email.php

Code: Select all

ob_start();
///////////////////////////
//Begin Configuration
///////////////////////////

// Your email
$to = "webmaster@tx3guilds.com" . ", " . "bw.gimpy@gmail.com" . ",";

// Email Subject
$subject = "Game Directory filing" . "TX3Guilds.com";

// Server name, to display in the headers
$server_name = "TX3Guilds.com";

///////////////////////////
//End Configuration
///////////////////////////

if (!empty($_POST['submit']) || !empty($_GET['submit']))
	{
	$action = (!empty($_POST['submit'])) ? $_POST['submit'] : $_GET['submit'];
	}
else
	{
	$action = '';
	}

$build_message = false;
if($action != "")
	{
	$build_message = true;
	$message = $_POST['games'];
	$name = $_POST['name'];
	$email = $_POST['email'];
	$website = $_POST['website'];
	//$time = time();
	$date = date("F j, Y", time());
	$headers = "MIME-Version: 1.0\r\n";
	$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
	$headers .= "From: $email\r\n";
	$headers .= "X-mailer: " . $server_name . " Server\r\n";
	}

if($build_message)
	{
/* message */
$message = "
Sender Name: $name\n 
Sender E-Mail: $email\n 
Date Sent: $date\n 
Information:\n----------------------------------------\nGame: $message \n Website $website\n";

	if(mail($to, $subject, $message, $headers))
		{
		//$result = "<b>Thank you</b>.<br />Someone will contact you soon.<br />TX3guilds Staff";
		header("Location: submit.php?form=email");
		die();
		}
	else
		{
		$result = "Sorry: An error occured, please try again later.";
		}
	}
// Output a result Message
//header("Location: index2.php");
print $result;
ob_end_flush();
And here is thanks.php

Code: Select all

<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="5;URL=http://www.tx3guilds.com/index2.php">
</head>
<body>
<div>
<b>Thank you</b>

Code: Select all

<?php $_GET['name']?>

Code: Select all

.<br />
Someone will contact you soon.<br />
Page will automatically refresh in 5 seconds.
<br />TX3guilds Staff
</div>
</body>
</html>
Now the email function still works, thats not the problem. The problem is that the user doesnt see the thanks.php because the email case shows up and clears the form. The site is http://www.tx3guilds.com/_build/submit.php so you can see what I'm talking about. Also, if someone could explain why its doing that so I may understand for future purposes.

P.S. I know the email and site are not checked for a correct form yet, thats next on my list.

Thanks in advance,
bryan

Posted: Wed Feb 21, 2007 3:37 am
by louie35
change this:

Code: Select all

if(mail($to, $subject, $message, $headers)) 
                { 
                //$result = "<b>Thank you</b>.<br />Someone will contact you soon.<br />TX3guilds Staff"; 
                  ob_end_clean();                
                  header("Location: submit.php?form=email"); 
                  exit(); 
                } 
        else 
                { 
                $result = "Sorry: An error occured, please try again later."; 
                } 
        }
then change the switch as well

Code: Select all

$form = "";
if(isset($_GET['form'])){ $form = $_GET['form'];}

switch ($form) { 
        case "email": 
          require_once "thanks.php";
        break;
 
        default: 
          require_once "comm_form.php"; 
        break; 
        }

Posted: Wed Feb 21, 2007 3:37 am
by onion2k
Where is $form set?

Posted: Wed Feb 21, 2007 9:41 am
by Gimpy
Form is set at submit.php