[Solved]switch not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

[Solved]switch not working

Post 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
Last edited by Gimpy on Wed Feb 21, 2007 9:40 am, edited 1 time in total.
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post 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; 
        }
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Where is $form set?
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Post by Gimpy »

Form is set at submit.php
Post Reply