Page 1 of 1

php form submit redirection

Posted: Sat Sep 09, 2006 12:49 pm
by ankrah
Hello,

I have this php form in the works and I want it to redirect to another page on submission
this is what I have

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><?php
			if ($_POST['submit']) {
   			$required_fields = explode(",", $_POST['required']);

 			$error = 0;

 			foreach($required_fields as $fieldname) {
   		    if ($_POST[$fieldname] == "") {
       	    $error++;
    		 }
			  }
			   if ($error == 0) {
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) {
	    mail("art@mellontech.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>");
		  header("Location:http://www.mellonhosting.com/art/thanks.php?name=$_POST[name]"); 
         exit;
	  } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>";
      }
	   } else {
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely.";
   }
}
?>
<head>
<?php
			if ($_POST['submit']) {
   			$required_fields = explode(",", $_POST['required']);

 			$error = 0;

 			foreach($required_fields as $fieldname) {
   		    if ($_POST[$fieldname] == "") {
       	    $error++;
    		 }
			  }
			   if ($error == 0) {
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) {
	    mail("art@mellontech.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>");
		  header("Location:http://www.domain.com/thanks.php?name=$_POST[name]"); 
         exit;
	  } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>";
      }
	   } else {
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely.";
   }
}
?>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>



<body>

<br><br>
<?=$errormessage?>
<br>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table width="500" border="0" cellpadding="5" cellspacing="0">
<tr><td>Your name:</td><td><input type="text" name="name" value="<?=$_POST['name']?>"></td></tr>
<tr><td>Your email:</td><td><input type="text" name="email" value="<?=$_POST['email']?>"><td><tr>
<tr><td>Your message:</td><td><textarea name="message"><?=$_POST['message']?></textarea></td></tr></table>
<input type="hidden" name="required" value="name,email,message">
<input type="submit" name="submit" value="submit"> 

</body>
</html>
as you can see its simple but \

header("Location:http://www.domain.com/thanks.php?name=$_POST[name]");
exit;
is giving me an error so I cant use that any other way to have it redirect to another page on submission.... please give code examples to help me understand

Posted: Sat Sep 09, 2006 1:34 pm
by tecktalkcm0391

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>

Code: Select all

<?php 
         if ($_POST['submit']) { 
            $required_fields = explode(",", $_POST['required']); 

          $error = 0; 

          foreach($required_fields as $fieldname) { 
             if ($_POST[$fieldname] == "") { 
              $error++; 
           } 
           } 
            if ($error == 0) { 
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) { 
       mail("art@mellontech.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>"); 
        header("Location:http://www.mellonhosting.com/art/thanks.php?name=$_POST[name]"); 
         exit; 
     } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>"; 
      } 
      } else { 
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely."; 
   } 
} 
?>

Code: Select all

<head>

Code: Select all

<?php 
         if ($_POST['submit']) { 
            $required_fields = explode(",", $_POST['required']); 

          $error = 0; 

          foreach($required_fields as $fieldname) { 
             if ($_POST[$fieldname] == "") { 
              $error++; 
           } 
           } 
            if ($error == 0) { 
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) { 
       mail("art@mellontech.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>"); 
        header("Location:http://www.domain.com/thanks.php?name=$_POST[name]"); 
         exit; 
     } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>"; 
      } 
      } else { 
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely."; 
   } 
} 
?>

Code: Select all

<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 



<body> 

<br><br>

Code: Select all

<?=$errormessage?>

Code: Select all

<br> 

<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
<table width="500" border="0" cellpadding="5" cellspacing="0"> 
<tr><td>Your name:</td><td><input type="text" name="name" value="<?=$_POST['name']?>"></td></tr> 
<tr><td>Your email:</td><td><input type="text" name="email" value="<?=$_POST['email']?>"><td><tr> 
<tr><td>Your message:</td><td><textarea name="message"><?=$_POST['message']?></textarea></td></tr></table> 
<input type="hidden" name="required" value="name,email,message"> 
<input type="submit" name="submit" value="submit"> 

</body> 
</html>
Ok, now that I made it easier for me to read... you need to fix a few things....

1.) don't use <? to start a php code, always use <?php because that will be the only one you will be able to use in new editions of php, or from what i heard...

2.) Why do you have the PHP Script in two places?

3.) You should just put all first running scripts like that code before any html.

4.) Try using header like this:

Code: Select all

header("Location: http://www.mellonhosting.com/art/thanks.php?name=".$_POST[name]."");
So that the variable isn't in the " ". It just works better for me, and if you forget and use ' ' you won't get problems.

5.) I alwasy would put ob_start(); at the first line of a site within php code that buffers info and gives you less problems

so now you shoul have:

Code: Select all

<?php 
         if ($_POST['submit']) { 
            $required_fields = explode(",", $_POST['required']); 

          $error = 0; 

          foreach($required_fields as $fieldname) { 
             if ($_POST[$fieldname] == "") { 
              $error++; 
           } 
           } 
            if ($error == 0) { 
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) { 
       mail("art@mellontech.com" , "Message from Web Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>"); 
        header("header("Location: http://www.mellonhosting.com/art/thanks.php?name=".$_POST[name]."");"); 
         exit; 
     } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>"; 
      } 
      } else { 
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely."; 
   } 
} 
?>

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>

Code: Select all

<head><title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
</head> 



<body> 

<br><br>

Code: Select all

<?php print($errormessage); ?>

Code: Select all

<br> 

<form action="<?php print($_SERVER['PHP_SELF']); ?>" method="post"> 
<table width="500" border="0" cellpadding="5" cellspacing="0"> 
<tr><td>Your name:</td><td><input type="text" name="name" value="<?php print( $_POST['name']); ?>"></td></tr> 
<tr><td>Your email:</td><td><input type="text" name="email" value="<?php print($_POST['email']); ?>"><td><tr> 
<tr><td>Your message:</td><td><textarea name="message"><?php print($_POST['message']); ?></textarea></td></tr></table> 
<input type="hidden" name="required" value="name,email,message"> 
<input type="submit" name="submit" value="submit"> 

</body> 
</html>

Posted: Sat Sep 09, 2006 1:37 pm
by ankrah
wow i didnt realize i had it twice i thought i deleted the one lol

but thanks ill try that

THANKS!

Posted: Sat Sep 09, 2006 1:41 pm
by ankrah
awesome thanks a lot ... its always the stupid little stuff that i miss lol...

im still just learning php so that stuff you said will be a great help in the future

thanks again

Ankrah

ok a new problem has arrived

Posted: Sat Sep 09, 2006 2:28 pm
by ankrah
ok heres what we got to work with now

Code: Select all

<?php 
         if ($_POST['submit']) { 
            $required_fields = explode(",", $_POST['required']); 

          $error = 0; 

          foreach($required_fields as $fieldname) { 
             if ($_POST[$fieldname] == "") { 
              $error++; 
           } 
           } 
            if ($error == 0) { 
      if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) { 
       mail("art@mellontech.com" , "Contest Entry Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>"); 
        header("Location: http://www.mellonhosting.com/art/thanks.php?name=".$_POST[name]."");
         exit; 
     } else { 
         $errormessage = "<b>The email address you entered does not appear to be valid<br></b>"; 
      } 
      } else { 
      $errormessage = "<b>You have left some required fields in the form blank! Please fill in the form completely."; 
   } 
} 
?>

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>



<body>

<br><br>

Code: Select all

<?=$errormessage?>

Code: Select all

<br>


<table width="750" border="0" cellpadding="0" cellspacing="0" id="wrapper">
    <tr>
      <td width="9" rowspan="3" valign="top" class="silverbar"><img src="../../../../images/silverbar.jpg" width="9px" height="356px"></td>
      <td valign="top" class="tablebg">
	  <div id="masthead">

	  	<div id="logo"><img src="../../../../images/mellontech_logo2.jpg" width="179px" height="181px" alt="Mellon Technology Service" /></div>
		<div id="flash">&nbsp;</div>
		<div class="style2" id="mainNav">
			<ul>
				<li>
				<p style="text-align: center"><a href="#" class="style3">Enter to Win! </a></li>
				</ul>
	  	</div>	
	  </div>

	  <div id="content">
	  	<center>
	  	  <h1>Marketing Makeover By Mellon Technology Service! </h1>
	  <P><center><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table width="500" border="0" cellpadding="5" cellspacing="0">
<tr><td>Name:</td><td><input type="text" name="name" size="50" value="<?=$_POST['name']?>"></td></tr>
<tr><td>Organization:</td><td><input type="text" name="org" size="40" value="<?=$_POST['org']?>"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email" size="40" value="<?=$_POST['email']?>"><td><tr>
<tr><td> Address:</td><td><input type="text" name="addr" size="40" value="<?=$_POST['addr']?>"><td><tr>
<tr><td>City:</td><td><input type="text" name="city" size="25" value="<?=$_POST['city']?>">&nbsp;&nbsp;State:<input type="text" name="state" size="2" maxlength="2" value="<?=$_POST['state']?>"><td><tr>
<tr><td>5-Digit Zipcode:</td><td><input type="text" name="zip" size="5" maxlength="5" value="<?=$_POST['zip']?>"><td><tr>
<tr><td>10-Digit Phone Number:</td><td><input type="text" name="area" size="3" maxlength="3" value="<?=$_POST['area']?>">-<input type="text" name="phone1" size="3" maxlength="3" value="<?=$_POST['phone1']?>">-<input type="text" name="phone2" size="4" maxlength="4" value="<?=$_POST['phone2']?>"><td><tr>
<tr><td>Why you need a Marketing Makeover:</td><td><textarea rows="15" cols="30" name="message"><?=$_POST['message']?></textarea></td></tr></table>
<input type="hidden" name="required" value="name,email,message,org,addr,city,state,zip,area,phone1,phone2">
<input type="submit" name="submit" value="submit"> </P>	
	  	  <p align="center"><strong>You may also enter by submitting this information to: </strong></p>
	  	  <p align="center"><strong>1606 West State Street, Olean, NY 14760</strong></p>
	  	  <p align="center"><strong>716-372-5996 or toll free at 888-372-5996</strong></p>
	  	  <p align="center"><strong> e-mail: <a href="mailto:info@mellontech.com">info@mellontech.com</a></strong></p>

	  	  <p align="center">&nbsp;</p>
	  	  <p align="center">&nbsp;</p>
	  	  <p>&nbsp;</p>
	  	</center>
	  </div>
	  <div id="leftmenubar">
	  		<div id="subNav">
		  	  <ul>
			  <li><a href="http://contest.mellontech.com">Home</a></li>

		  	  <li><a href="http://contest.mellontech.com/examples.html">Corporate ID Examples</a></li>
			  <li><a target="_blank" href="http://www.whatisimc.com">What Is IMC?</a></li>
			  <li><a href="http://contest.mellontech.com/enter.php">Enter to Win </a></li>
			  <li><a href="http://contest.mellontech.com/terms.html">Terms & Conditions</a></li>
		      </ul>
		  	</div>

			<div align="center"><img src="../../../../images/ReliabilitySeal.GIF" width="90px" height="32px" alt="BBB OnLine Reliability Program" />	    	</div>
	  </div>	  </td>
      <td width="9" rowspan="3" valign="top" class="silverbar"><img src="../../../../images/silverbar.jpg" width="9" height="356"></td>
    </tr>
	<tr valign="top">
		<td colspan="2" class="footercell">
			<div id="footer">Copyright &copy; 2006 Mellon Technology Service</div>		</td>

	</tr>
</body>
</html>


no i want to make each of the fields information display in the body of the email.... as of right now only the message is an im pretty sure the area that needs changed is

if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) {
mail("art@mellontech.com" , "Contest Entry Form", $_POST['message'], "From: $_POST[name] <$_POST[email]>");

but i tried adding

if (strstr($_POST['email'], "@") and strstr($_POST['email'], ".")) {
mail("art@mellontech.com" , "Contest Entry Form", $_POST['name], $_POST['org], $_POST['message'], "From: $_POST[name] <$_POST[email]>");

but that just gives me errors..


any suggestions anyone?

Posted: Sun Sep 10, 2006 12:09 am
by tecktalkcm0391
Use PHP Mailer and not the Mail(); Function. PHP Mail(); function uses bandwidth and PHP Mailer uses your severs STMP mail server.

Posted: Tue Sep 12, 2006 3:11 pm
by ankrah
have a link or anything that would help me figure out how to do that?

bandwith isnt a problem though and would like to just be able to add the information from those fields into the email