Forms in php
Posted: Thu Sep 26, 2002 9:30 pm
Hello, I am a beginner in php and I am currently working on this project of creating a form. I have the form created and it”s working the way it’s suppose to work by the way I have created it. Now what I would like to do is after the form has been validated I would like to pull the completed form back up under the title something like here is the information that you submitted please check for spelling errors and resubmit. I would like to do this by using an update form button and then submit the form after corrections have been made. I am not asking for some one to write it for me just a few suggestions on how to do what I would like to do. Here is the code that I have used to get it going.
<html>
<head>
<title>application</title>
</head>
<body>
<FORM METHOD="POST" ACTION="application.php">
<h1>Application For Employment</h1>
<table>
<p align="right">Date of Application: <input type="text" name="T1" size="12"></p>
<p>Position applied for: <input type="text" name="T2" size="73"> Salary
Desired: <input type="text" name="T3" size="11"> Minimum Accepted Salary:
<input type="text" name="T4" size="11"></p>
<p>How did you hear about us: <select size="1" name="D1" multiple>
<option>Radio</option>
<option>TV</option>
<option>Newspaper</option>
<option>Other</option>
</select></p>
<p> </p>
<p> </p>
<tr>
<td><b>Last name:</b></td>
<td><INPUT TYPE="TEXT" NAME="lastname" size="20"></td>
</tr>
<tr>
<td><b>First name:</b></td>
<td><INPUT TYPE="TEXT" NAME="firstname" size="20"></td>
</tr>
<tr>
<td><b>Middle name:</b></td>
<td><INPUT TYPE="TEXT" NAME="middlename" size="20"></td>
</tr>
<tr>
<td><b>Maiden name:</b></td>
<td><INPUT TYPE="TEXT" NAME="maidenname" size="20"></td>
</tr>
<tr>
<td><b>Primary Email:</b></td>
<td><INPUT TYPE="TEXT" NAME="email" size="20"></td>
<td WIDTH="20"> </td>
<td>Secondary Email:</td>
<td><INPUT TYPE="TEXT" NAME="secondaryemail" size="20"></td>
</tr>
<tr>
<td>Home Address:</td>
<td><INPUT TYPE="TEXT" NAME="homeaddress1"></td>
</tr>
<tr>
<td></td>
<td><INPUT TYPE="TEXT" NAME="homeaddress2"></td>
</tr>
<tr>
<td>City:</td>
<td><INPUT TYPE="TEXT" NAME="homecity"></td>
</tr>
<tr>
<td>County:</td>
<td><INPUT TYPE="TEXT" NAME="homecounty"></td>
</TR>
<tr>
<td>State:</td>
<td><INPUT TYPE="TEXT" NAME="homestate"></td>
</tr>
<tr>
<td>Postal</td>
<td><INPUT TYPE="TEXT" NAME="homepostal"></td>
</tr>
</table>
<br>
<br>
<br>
<INPUT TYPE= "SUBMIT" VALUE="Submit">
<br>
<br>
<INPUT TYPE= "RESET" VALUE="Clear the form">
</form>
</body>
</html>
<?php
include "application.inc.txt";
function validate_form()
{
global $lastname, $firstname, $middlename;
$errors=0;
if (!trim($lastname))
{
echo "<BR><B>Last name</B> is required.";
$errors++;
}
if (!trim($firstname))
{
echo "<BR><B>First name</B> is required.";
$errors++;
}
if (!trim($middlename))
{
echo "<BR><B>Middle name</B> is required.";
$errors++;
}
switch ($errors)
{
case 0:
return TRUE;
case 1:
echo "<BR><BR><BR>Please use your ";
echo "browser's back button to return to ";
echo "the form, correct the error, and ";
echo "re-submit the form. ";
return FALSE;
default:
echo "<BR><BR><BR>Please use your ";
echo "browser's back button to return to ";
echo "the form, correct the error, and ";
echo "re-submit the form. ";
return FALSE;
}
}
function update_database()
{
echo "<BR>Updating database....";
}
$ok = validate_form();
if ($ok)
update_database();
?>
</body>
</hmtl>
<html>
<head>
<title>application</title>
</head>
<body>
<html>
<head>
<title>application</title>
</head>
<body>
<FORM METHOD="POST" ACTION="application.php">
<h1>Application For Employment</h1>
<table>
<p align="right">Date of Application: <input type="text" name="T1" size="12"></p>
<p>Position applied for: <input type="text" name="T2" size="73"> Salary
Desired: <input type="text" name="T3" size="11"> Minimum Accepted Salary:
<input type="text" name="T4" size="11"></p>
<p>How did you hear about us: <select size="1" name="D1" multiple>
<option>Radio</option>
<option>TV</option>
<option>Newspaper</option>
<option>Other</option>
</select></p>
<p> </p>
<p> </p>
<tr>
<td><b>Last name:</b></td>
<td><INPUT TYPE="TEXT" NAME="lastname" size="20"></td>
</tr>
<tr>
<td><b>First name:</b></td>
<td><INPUT TYPE="TEXT" NAME="firstname" size="20"></td>
</tr>
<tr>
<td><b>Middle name:</b></td>
<td><INPUT TYPE="TEXT" NAME="middlename" size="20"></td>
</tr>
<tr>
<td><b>Maiden name:</b></td>
<td><INPUT TYPE="TEXT" NAME="maidenname" size="20"></td>
</tr>
<tr>
<td><b>Primary Email:</b></td>
<td><INPUT TYPE="TEXT" NAME="email" size="20"></td>
<td WIDTH="20"> </td>
<td>Secondary Email:</td>
<td><INPUT TYPE="TEXT" NAME="secondaryemail" size="20"></td>
</tr>
<tr>
<td>Home Address:</td>
<td><INPUT TYPE="TEXT" NAME="homeaddress1"></td>
</tr>
<tr>
<td></td>
<td><INPUT TYPE="TEXT" NAME="homeaddress2"></td>
</tr>
<tr>
<td>City:</td>
<td><INPUT TYPE="TEXT" NAME="homecity"></td>
</tr>
<tr>
<td>County:</td>
<td><INPUT TYPE="TEXT" NAME="homecounty"></td>
</TR>
<tr>
<td>State:</td>
<td><INPUT TYPE="TEXT" NAME="homestate"></td>
</tr>
<tr>
<td>Postal</td>
<td><INPUT TYPE="TEXT" NAME="homepostal"></td>
</tr>
</table>
<br>
<br>
<br>
<INPUT TYPE= "SUBMIT" VALUE="Submit">
<br>
<br>
<INPUT TYPE= "RESET" VALUE="Clear the form">
</form>
</body>
</html>
<?php
include "application.inc.txt";
function validate_form()
{
global $lastname, $firstname, $middlename;
$errors=0;
if (!trim($lastname))
{
echo "<BR><B>Last name</B> is required.";
$errors++;
}
if (!trim($firstname))
{
echo "<BR><B>First name</B> is required.";
$errors++;
}
if (!trim($middlename))
{
echo "<BR><B>Middle name</B> is required.";
$errors++;
}
switch ($errors)
{
case 0:
return TRUE;
case 1:
echo "<BR><BR><BR>Please use your ";
echo "browser's back button to return to ";
echo "the form, correct the error, and ";
echo "re-submit the form. ";
return FALSE;
default:
echo "<BR><BR><BR>Please use your ";
echo "browser's back button to return to ";
echo "the form, correct the error, and ";
echo "re-submit the form. ";
return FALSE;
}
}
function update_database()
{
echo "<BR>Updating database....";
}
$ok = validate_form();
if ($ok)
update_database();
?>
</body>
</hmtl>
<html>
<head>
<title>application</title>
</head>
<body>