Location: PHPKode > scripts > Advanced Form Handling with PHP > advanced-form-handling-with-php/php_publ040406.htm
<html>

<head>
<meta http-equiv="Content-Language" content="de-ch">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>PHP Advanced Form Handling</title>
</head>

<body>

<table border="0" width="100%">
  <tr>
    <td width="100%"><font face="Arial" size="1">A few weeks ago I was looking
      for a form solution which is capable to show and hide several controls
      including disabling and enabling some elements at the right time. The
      subject was personalized pages with personal page design. Because I'm not
      very devoted to JavaScript I decided to solve the problem with PHP code,
      which fairly easy to do. See the several steps on the screenshots beneath.<br>
      To maintain the result I use mainly parameters and variables, some control
      the validation, some control the behaviour of the form. As you see in the <b>first</b>
      <b>part</b> the code is concerning about two things. Disable the Radio
      Buttons and validate the user and passwords. The rest is controlling the
      activities when the user is ready to make his choice and has made his
      choice. The <b> second part</b> of the scripts snippets you see here (the complete
      script is <a href="#load">downloadable</a>)&nbsp;handles the reset event
      programmatically.<br>
      The controls which have to be opened and closed act after the submission
      of the delivered variables. That's it. Database action and other stuff is
      all yours. <i>Best regards Claudio Biesele</i></font></td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
      <p><font face="Arial" size="1"><b>First Part:</b></font></p>
      <p><font face="Arial" size="1">&lt;?php<br>
	$message = '';<br>
	$gewmuster = $_POST['FarbMuster'];<br>
      <br>
		 if (isset($_POST['FormNewUser']))<br>
	 		{<br>
	 			$enable1 = 'disabled';<br>
				$enable2 = 'disabled';<br>
	 			if($_POST['textUser'] == '')<br>
	 			{<br>
	 				$stop1 = "*";<br>
	 				$message = "Username required.";<br>
	 			}<br>
	 			else  if($_POST['textPW1'] == '' || $_POST['textPW2'] == ''  )<br>
	 			{<br>
	 				$stop2 = "*";<br>
	 				$stop3 = "*";<br>
	 				$message = "Passwords required!";<br>
	 			}<br>
	 			else  if($_POST['textPW1'] != $_POST['textPW2'])<br>
	 			{<br>
	 				$stop2 = "*";<br>
	 				$stop3 = "*";<br>
	 				$message = "Passwords are not identical!";<br>
	 			}<br>
	 			else  if($_POST['textPW1'] == $_POST['textPW2'])<br>
	 			{<br>
	 		 		$enable1 = 'enabled';<br>
	 		 		$enable2 = 'enabled';<br>
	 			}<br>
	 			if($_POST['auswahl'] &lt; '1' &amp;&amp; $_POST['textUser'] != '' &amp;&amp; $_POST['textPW1'] != '' &amp;&amp; $_POST['textPW1'] == $_POST['textPW2'])<br>
	 			{<br>
	 				$stop4 = "*";<br>
	 				$pauswahl = '1';<br>
	 				$message = "Please choose your personal skin color!";<br>
	  			}<br>
	  			if($_POST['auswahl'] == '1')<br>
	 			{<br>
	 				$pauswahl = '0';<br>
	 				$check1 = 'unchecked';<br>
		  		}<br>
		  		if($_POST['auswahl'] == '1' &amp;&amp; $_POST['FarbMuster'] > '0')<br>
	 			{<br>
	 				$check1 = 'checked';&nbsp;<br>
	 				$message = "You have been registered with the skin color number $gewmuster!";<br>
	 				// sql code goes here&nbsp;<br>
		  		}<br>
		  		else if($_POST['auswahl'] == '2')<br>
	 			{<br>
	 				$check2 = 'checked';<br>
	 				$message = "You have been registered without a personal skin color!";<br>
	 				// sql code goes here<br>
		  		}&nbsp;<br>
		  	}<br>
  ?></font></td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
      <p><font face="Arial" size="1"><b>Second Part:</b></font></p>
      <p><font face="Arial" size="1">  &lt;?php<br>
	 if (isset($_POST['ResetNew']))<br>
	 {<br>
	  	$textUser = '';<br>
	  	$textPW1 = '';<br>
	  	$textPW2 = '';<br>
	  	$message = '';<br>
	  	$enable1 = 'disabled';<br>
		$enable2 = 'disabled';<br>
      $auswahl = '';<br>
		$gewmuster = '0';<br>
	}<br>
      ?></font></td>
  </tr>
  <tr>
    <td width="100%">
      <hr>
      <p><img border="0" src="pub_form040406_1.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>1. Step:</b> Radio Buttons
      have to be enabled.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_2.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>2. Step:</b> The user will
      be validated ...</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_3.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>3. Step:</b> Passwords are
      required ...</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_4.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>4. Step:</b> Passwords have
      to be equal .....</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_5.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>5. Step:</b> After form is
      validated Radio Buttons are enabled</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_6.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>6. Step:</b> User will have
      no special skin design.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_7.jpg" width="430" height="330"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>7. Step:</b> Alternative:
      User will choose his preferred skin design.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_8.jpg" width="430" height="430"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>8. Step:</b> User has made
      his decision.</font></td>
  </tr>
  <tr>
    <td width="100%"><img border="0" src="pub_form040406_9.jpg" width="430" height="230"></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1"><b>9. Step:</b> Confirmation of
      the users decision.</font></td>
  </tr>
  <tr>
    <td width="100%"><font face="Arial" size="1">Download the full script at <a href="http://www.fastproject.ch/publikationen/FormHandling.zip" target="_blank">www.fastproject.ch</a><a name="load"></a>.
      The downloaded script is free from Copyright restrictions, Zurich, 04th of
      April 2006.</font></td>
  </tr>
</table>

</body>

</html>
Return current item: Advanced Form Handling with PHP