Location: PHPKode > scripts > Advanced Form Handling with PHP > advanced-form-handling-with-php/FormHandling.php
<?php
if ($_SERVER["REQUEST_METHOD"]!="POST") 
	{
		$enable1 = 'disabled';
		$enable2 = 'disabled';
		$pauswahl = '0';
	}
?>
<?php
	$textUser = $_REQUEST['textUser'];
	$textPW1 = $_REQUEST['textPW1'];
	$textPW2 = $_REQUEST['textPW2'];
	$auswahl = $_REQUEST['auswahl'];
	$pauswahl = $_REQUEST['pauswahl'];
	$check1 = $_REQUEST['check1'];
 	$message = '';
	$gewmuster = $_POST['FarbMuster'];

		 if (isset($_POST['FormNewUser']))
	 		{
	 			$enable1 = 'disabled';
				$enable2 = 'disabled';
	 			if($_POST['textUser'] == '')
	 			{
	 				$stop1 = "*";
	 				$message = "Username required.";
	 			}
	 			else  if($_POST['textPW1'] == '' || $_POST['textPW2'] == ''  )
	 			{
	 				$stop2 = "*";
	 				$stop3 = "*";
	 				$message = "Passwords required!";
	 			}
	 			else  if($_POST['textPW1'] != $_POST['textPW2'])
	 			{
	 				$stop2 = "*";
	 				$stop3 = "*";
	 				$message = "Passwords are not identical!";
	 			}
	 			else  if($_POST['textPW1'] == $_POST['textPW2'])
	 			{
	 		 		$enable1 = 'enabled';
	 		 		$enable2 = 'enabled';
	 			}
	 			if($_POST['auswahl'] < '1' && $_POST['textUser'] != '' && $_POST['textPW1'] != '' && $_POST['textPW1'] == $_POST['textPW2'])
	 			{
	 				$stop4 = "*";
	 				$pauswahl = '1';
	 				$message = "Please decide if you want a personal skin color!";
	  			}
	  			if($_POST['auswahl'] == '1')
	 			{
	 				$pauswahl = '0';
	 				$check1 = 'checked';
		  		}
		  		if($_POST['auswahl'] == '1' && $_POST['FarbMuster'] > '0')
	 			{
	 				$check1 = 'checked';	 				
	 				$message = "You have been registered with the skin color number $gewmuster!";
		  		}
		  		else if($_POST['auswahl'] == '2')
	 			{
	 				$check2 = 'checked';
	 				$message = "You have been registered without a personal skin color!";
		  		}	  		
		  	}
  ?>
  <?php
	 if (isset($_POST['ResetNew']))
	 {
	  	$textUser = '';
	  	$textPW1 = '';
	  	$textPW2 = '';
	  	$message = '';
	  	$enable1 = 'disabled';
		$enable2 = 'disabled';
		$auswahl = '';
		$gewmuster = '0';
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<meta name="generator" content="Adobe GoLive 6">
		<title>Handling complex forms with PHP</title>
		<link href="FormHandling.css" rel="stylesheet" media="screen">
	</head>
	<body bgcolor="white" text="black" link="blue" vlink="#ff00ff" alink="red" leftmargin="40" marginheight="40" marginwidth="40" topmargin="40">
		<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST" name="FormNewUser">
			<table width="410" border="0" cellspacing="2" cellpadding="0" bgcolor="#dcdcdc">
				<tr>
					<td class="td1" colspan="2" width="392"><b>User Registration</b></td>
					<td width="10">&nbsp;</td>
				</tr>
				<tr>
					<td class="td1" width="150">Username</td>
					<td class="td1" width="240"><input type="hidden" name="pauswahl" value='<?php  echo htmlspecialchars($pauswahl);?>' size="2"><input class="inp" type="text" name="textUser" value='<?php  echo htmlspecialchars($textUser);?>' size="30" tabindex="1"></td>
					<td class="td1" width="10"><?php  echo htmlspecialchars($stop1);?>&nbsp;</td>
				</tr>
				<tr>
					<td class="td1"  width="150">Password ...</td>
					<td class="td1"  width="240"><input class="inp" type="password" name="textPW1" value='<?php  echo htmlspecialchars($textPW1);?>' size="30" tabindex="2"></td>
					<td class="td1" width="10"><?php  echo htmlspecialchars($stop2);?>&nbsp;</td>
				</tr>
				<tr>
					<td class="td1" width="150">... repeat it</td>
					<td class="td1" width="240"><input class="inp" type="password" name="textPW2" value='<?php  echo htmlspecialchars($textPW2);?>' size="30" tabindex="3"></td>
					<td class="td1" width="10"><?php  echo htmlspecialchars($stop2);?>&nbsp;</td>
				</tr>
				<tr>
					<td class="td1" width="150"><input type='hidden' name='FarbMuster' value='<?php  echo htmlspecialchars($gewmuster);?>' size='2'>Want your own skin color?</td>
					<td class="td1" width="240"><input type="radio" name="auswahl" value="1" <?php  echo htmlspecialchars($enable1);?> <?php  echo htmlspecialchars($check1);?> tabindex="4"> Yes <input type="radio" name="auswahl" value="2" <?php  echo htmlspecialchars($enable2);?> <?php  echo htmlspecialchars($check2);?>  tabindex="5"> No</td>
					<td class="td1" width="10"><?php  echo htmlspecialchars($stop4);?>&nbsp;</td>
				</tr>
				<tr>
					<td class="td1" width="150"><input class="btn" type="submit" name="ResetNew"  value="Reset - Close"></td>
					<td class="td1" width="240"><input class="btn" type="submit" name="FormNewUser" value="Register"></td>
					<td class="td1" width="10">&nbsp;</td>
				</tr>
			</table>
			<p></p>
<!-- Start Farbmuster Auswahl -->
<?php
if(isset($_POST['auswahl']));
{
 if ($_POST['auswahl'] == '1' && $_POST['pauswahl'] == '1' || $_POST['ok1'] || $_POST['ok2'] || $_POST['ok3'] || $_POST['ok4'])
 {
	echo ("
			<table width='158' border='0' cellspacing='0' cellpadding='0' align='left'>
				<tr>
				<td class='td2' colspan='2'><strong><input type='hidden' name='check1' value='checked' size='2'>Choose skin color</strong></td>
			</tr>
				<tr>
		
				<td class='td2'>Spring theme</td>
				<td class='td2'><input class='btn' type='submit' name='ok1' value='ok'></td>
			</tr>
				<tr>
			
				<td class='td2'>Summer theme</td>
				<td class='td2'><input class='btn' type='submit' name='ok2' value='ok'></td>
			</tr>
				<tr>
				
				<td class='td2'>Autumn theme</td>
				<td class='td2'><input class='btn' type='submit' name='ok3' value='ok'></td>
			</tr>
				<tr>
			
				<td class='td2'>Winter theme</td>
				<td class='td2'><input class='btn' type='submit' name='ok4' value='ok'></td>
			</tr>
			</table>
			");}}
  ?>
<!-- Ende Farbmuster Auswahl -->
<!-- Start Farbmuster Winter -->
<?php
   if ($_POST['ok4'] )
       {
      $muster = '4';
	echo ("<table width='250' border='0' cellspacing='0' cellpadding='0'>
			<tr>
				<td class='tdfm' colspan='2' width='254'><input type='hidden' name='check1' value='checked' size='2'><input type='hidden' name='FarbMuster' value='$muster' size='2'><b>Chosen skin: Winter</b></td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Background Color</td>
				<td class='h4' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontcolor Page</td>
				<td class='sf4' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Table Color</td>
				<td class='tf4' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' nowrap width='180'>Fontcolor Table</td>
				<td class='sft4' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fonttype</td>
				<td class='tdfm' bgcolor='white' width='70' height='20'>Arial, Helvetica, Geneva, Swiss, SunSans-<br>Regular</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontsize</td>
				<td class='tdfm' bgcolor='white' width='70' height='20'>14px</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Link Color</td>
				<td class='l4' bgcolor='white' width='70' height='20'>&nbsp;</td>
			</tr>
		</table>
		<p></p>
	</body>");}
  ?>
<!-- Ende Farbmuster Winter -->
<!-- Start Farbmuster Fruehling -->
  <?php
   if ($_POST['ok1'] )
    {
       $muster = '1';
	echo ("
  	<table width='250' border='0' cellspacing='0' cellpadding='0'>
  			<tr>
				<td class='tdfm' colspan='2' width='254'><input type='hidden' name='check1' value='checked' size='2'><input type='hidden' name='FarbMuster' value='$muster' size='2'><b>Chosen skin: Spring</b></td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Background Color</td>
				<td class='h1' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontcolor Page</td>
				<td class='sf1' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Table Color</td>
				<td class='tf1' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' nowrap width='180'>Fontcolor Table</td>
				<td class='sft1' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fonttype</td>
				<td class='tdfm' width='70' height='20'>Arial, Helvetica, Geneva, Swiss, SunSans-<br>Regular</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontsize</td>
				<td class='tdfm' width='70' height='20'>14px</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Link Color</td>
				<td class='l1' width='70' height='20'>&nbsp;</td>
			</tr>
		</table>");}
  ?>
<!-- Ende Farbmuster Fruehling -->
<!-- Start Farbmuster Sommer -->
 <?php
   if ($_POST['ok2'])
   {
       $muster = '2';
	echo ("
  <table width='250' border='0' cellspacing='0' cellpadding='0'>
  			<tr>
				<td class='tdfm' colspan='2' width='254'><input type='hidden' name='check1' value='checked' size='2'><input type='hidden' name='FarbMuster' value='$muster' size='2'><b>Chosen skin: Summer</b></td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Background Color</td>
				<td class='h2' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontcolor Page</td>
				<td class='sf2' width='70'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Table Color</td>
				<td class='tf2' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' nowrap width='180'>Fontcolor Table</td>
				<td class='sft2' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fonttype</td>
				<td class='sa2' width='70' height='20'>Courier New, Courier, Monaco</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontsize</td>
				<td class='tdfm' width='70' height='20'>14px</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Link Color</td>
				<td class='l2' width='70' height='20'>&nbsp;</td>
			</tr>
		</table>");}
  ?>
<!-- Ende Farbmuster Sommer -->
<!-- Start Farbmuster Herbst -->
   <?php
   if ($_POST['ok3'] )
   {
      	$muster = '3';
	echo ("
  <table width='250' border='0' cellspacing='0' cellpadding='0'>
  			<tr>
				<td class='tdfm' colspan='2' width='254'><input type='hidden' name='check1' value='checked' size='2'><input type='hidden' name='FarbMuster' value='$muster' size='2'><b>Chosen skin: Autumn</b></td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Background Color</td>
				<td class='h3' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontcolor Page</td>
				<td class='sf3' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Table Color</td>
				<td class='tf3' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' nowrap width='180'>Fontcolor Table</td>
				<td class='sft3' bgcolor='black' width='70' height='20'>&nbsp;</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fonttype</td>
				<td class='sa3' width='70'>Times New Roman, Georgia, Times</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Fontsize</td>
				<td class='tdfm' width='70' height='20'>14px</td>
			</tr>
			<tr>
				<td class='tdfm' width='180'>Link Color</td>
				<td class='l3' width='70' height='20'>&nbsp;</td>
			</tr>
		</table>");}
  ?>
  <!-- Ende Farbmuster Herbst -->
		</form>
		<p class="mess"><?php  echo htmlspecialchars($message);?></p>
		<p></p>
</html>
Return current item: Advanced Form Handling with PHP