Jump to content

Two page form


Praetorian

Recommended Posts

Well, I thought I had this figured out, until I ran it on a live web server. The form seems to work fine, it switches to the next page, only shows the errors for the fields on that page. But it turns out, when it coems time to mail the thing, the script forgets the values of the previous page. Is there any way for me to work this script so it will remember all the values when it comes time to mail the information? Do I need to use sessions for this?Here's the script.

				<form method="post" action="appmail.php" name="app">				<?php				include 'includes/appmail_vars.php'; // Includes declared variables and form values.				if(isset($submit_next)) // if they submit the first page, check for errors					{						if(empty($CharacterName) || !preg_match('#[a-z\'\-]+[\s]*#i', $CharacterName) || preg_match('#[\d]+#', $CharacterName))							$errors[] = "<h3>Your Character's name is invalid. Please try again.</h3>";						if(empty($Nation))							$errors[] = "<h3>Please choose a species for your character.</h3>";						if( (($Nation == "Ihthian") xor ($Nation == "Ikarrii")) and ($RaceIhthian == "void") and ($RaceIkarrii == "void"))							$errors[] = "<h3>The Species you have chosen Requires you to choose a sub-race.</h3>";						if( (($RaceIhthian == "void") and ($RaceIkarrii != "void")) and ($Nation == "Ihthian"))							$errors[] = "<h3>The sub-race you have chosen is invalid.</h3>";						if( (($RaceIkarrii == "void") and ($RaceIhthian != "void")) and ($Nation == "Ikarrii"))							$errors[] = "<h3>The sub-race you have chosen is invalid.</h3>";						if( (($RaceIhthian != "void") or ($RaceIkarrii != "void")) and ($Nation != "Ihthian") and ($Nation != "Ikarrii"))							$errors[] = "<h3>You cannot choose a sub race for that species.</h3>";						if( (($Nation == "Ihthian") xor ($Nation == "Ikarrii")) and ($RaceIhthian != "void") and ($RaceIkarrii != "void"))							$errors[] = "<h3>You have chosen too many sub-races.</h3>";												if( empty($CharacterAge) || preg_match('#[\D]+#', $CharacterAge))							$errors[] = "<h3>Please set your characters age.</h3>";						if( empty($Gender))							$errors[] = "<h3>Please select a gender for your character.</h3>";												if( empty($History))							$errors[] = "<h3>You have not entered your character's history.</h3>";												if( empty($WritingSample))							$errors[] = "<h3>You have not entered a writing sample.</h3>";										if( empty($errors)){								include 'includes/appform2.txt'; // if there are no errors, show the next page of the form						} else {								foreach($errors AS $e)									echo $e; // if there are errors, show only errors for first page									include "includes/appform1.txt"; // show the first page again, with the fields intact						}					}				elseif(isset($submit_mail)) // if they submit the second page, check for errors					{						if (empty($Email) || !preg_match($email_string, $Email)){							$errors[] = '<h3>Please Enter a Valid Email Address.</h3>';						}						if(!empty($errors))						{							foreach($errors AS $e)								  echo $e; // show only errors for second page					   			include "includes/appform2.txt"; // show second page again, with fields intact						}					}				elseif(empty($errors) && !empty($Email))					{						mail( "author@tsrealms.com",$Email,$Subject, "From: $Email" );						mail( $Email,"A copy of your Application", $Subject, "From: The Shattered Realms" );					   	echo $confirm_message; // confirm message is set in appmail_vars file.					}				else // if this is their first visit to the page, show the first page of the form					{						include 'includes/appform1.txt';					}				?>				</form>

EDIT: It occured to me I should probably show you the appmail_vars.php file too.

<?php$CharacterName = stripslashes($_REQUEST['CharacterName']);$Nation = $_REQUEST['Nation'];$RaceIhthian = $_REQUEST['RaceIhthian'];$RaceIkarrii = $_REQUEST['RaceIkarrii'];$Race = $RaceIhthian.$RaceKiil;$CharacterAge = $_REQUEST['CharacterAge'];$Gender = $_REQUEST['Gender'];$Guild = $_REQUEST['Guild'];$History = $_REQUEST['History'];$WritingSample = $_REQUEST['WritingSample'];$Email = $_REQUEST['Email'];$Alias = $_REQUEST['Alias'];$YourAge = $_REQUEST['YourAge'];$YourGender = $_REQUEST['YourGender'];$Icq = $_REQUEST['Icq'];$Aim = $_REQUEST['Aim'];$Msn = $_REQUEST['Msn'];$submit_next = $_REQUEST['submit_next'];$submit_mail = $_REQUEST['submit_mail'];$Subject = "~Character Information~\r\n\r\n\r\n~Name~\r\n$CharacterName\r\n\r\n~Nationality~\r\n$Nation\r\n\r\n~Race~\r\n$Race\r\n\r\n~Age~\r\n$CharacterAge\r\n\r\n~Gender~\r\n$Gender\r\n\r\n~Guild~\r\n$Guild\r\n\r\n~Brief History~\r\n$History\r\n\r\n~Writing Sample~\r\n$WritingSample\r\n\r\n\r\n~Personal Information~\r\n\r\n\r\n~Name/Alias~\r\n$Alias\r\n\r\n~Age~\r\n$YourAge\r\n\r\n~Age~\r\n$YourAge\r\n\r\n~ICQ~\r\n$Icq\r\n\r\n~AIM~\r\n$Aim\r\n\r\n~MSN~\r\n$Msn";$email_string = '#^[\d\w]+[\d\w\.+!=\#|$?%{^&}*`\'~-]*@[\d\w]{1,61}[\d\w.-]*[A-Z0-9]\.[A-Z]{2,6}$#i';$confirm_message = "<h1>Thank you for your application! One of the admins should be getting back to you via email within 24 hours. If you're accepted, you'll be given the link to register a user name on the message board. A copy of your application has been emailed to you.</h1>";$errors = Array();?>

Link to comment
Share on other sites

If there's an intermediate page between the form and the email script, then you're going to need to submit everything from the intermediate page to the email script. Just clicking a link or something isn't going to submit anything. Instead of a link you would need to write everything into hidden input tags and give a submit button to submit everything again. You can also store things in the session.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...