PHP Advanced Form Handling

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.
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 first part 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 second part of the scripts snippets you see here (the complete script is downloadable) handles the reset event programmatically.
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.
Best regards Claudio Biesele

First Part:

<?php
$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 choose your personal skin color!";
}
if($_POST['auswahl'] == '1')
{
$pauswahl = '0';
$check1 = 'unchecked';
}
if($_POST['auswahl'] == '1' && $_POST['FarbMuster'] > '0')
{
$check1 = 'checked'; 
$message = "You have been registered with the skin color number $gewmuster!";
// sql code goes here 
}
else if($_POST['auswahl'] == '2')
{
$check2 = 'checked';
$message = "You have been registered without a personal skin color!";
// sql code goes here

}
?>


Second Part:

<?php
if (isset($_POST['ResetNew']))
{
$textUser = '';
$textPW1 = '';
$textPW2 = '';
$message = '';
$enable1 = 'disabled';
$enable2 = 'disabled';
$auswahl = '';
$gewmuster = '0';
}
?>


Picture pub_form040406_1.jpg

1. Step: Radio Buttons have to be enabled.
Picture pub_form040406_2.jpg
2. Step: The user will be validated ...
Picture pub_form040406_3.jpg
3. Step: Passwords are required ...
Picture pub_form040406_4.jpg
4. Step: Passwords have to be equal .....
Picture pub_form040406_5.jpg
5. Step: After form is validated Radio Buttons are enabled
Picture pub_form040406_6.jpg
6. Step: User will have no special skin design.
Picture pub_form040406_7.jpg
7. Step: Alternative: User will choose his preferred skin design.
Picture pub_form040406_8.jpg
8. Step: User has made his decision.
Picture pub_form040406_9.jpg
9. Step: Confirmation of the users decision.
Download the full script at www.fastproject.ch. The downloaded script is free from Copyright restrictions, Zurich, 16th of November 2015.
Donate with PayPal:
placeholder