Hi there all...
i have an an edit.php form.
This form will have three text field, (first_name, Last_name, age)
and once submitted, it will go to update.php.
Now, i manage to check if any of the field is empty or not.
(incase if the user delete a field value and forgot to type sumthing...)
then it will return an error message, saying which field is empty,
so the user can press the back button
on the browser (any idea how to do this in php?)
and fill in any empty field.
But.. thats not fun...
i want the script to bring back the form,
and for the empty field,
it will say "Pleeze fill this field" beside the empty field textbox.
and so on..
and for the field that is NOT empty, it will retain the original value...
any idea how to do this...
here's my code, but it doesnt work well..
<?PHP
$new_first_name = $_POST['firstname'];
$new_last_name = $_POST['lastname'];
$new_age = $_POST['age'];
$id = $HTTP_GET_VARS['id'];
$err_count = 0;
if(isset($_POST['cancelbtn'])) {
print "CANCEL BUTTON was pressed";
} else {
if(isset($_POST['updatebtn'])) {
if (trim($new_first_name) == "") {
$err_msg_first_name = " Please Include first Name";
$new_first_name = " ";
$err_count = $err_count + 1;
echo "FIRST NAME is empty!";
echo "<BR>";
}
if (trim($new_last_name) == "") {
$err_count = $err_count + 1;
$new_last_name = " ";
$err_msg_last_name = " Please Include Last Name";
echo "LAST NAME is empty!";
echo "<BR>";
}
if ($err_count > 0) {
echo "<B>", $err_count, "</B>", " Errors Detected";
print "<form action=update.php?id=$id method=POST>";
Print "<BR>";
print "First Name: <input type=text name=firstname value=$new_first_name size=25 maxlength=25>";
echo $err_msg_first_name;
Print "<BR>";
print "Last Name: <input type=text name=lastname value=$new_last_name size=25 maxlength=25>";
echo $err_msg_last_name;
Print "<BR>";
print "Age: <input type=text name=age value=$new_age size=5 maxlength=5>";
print "<p>";
print "<input type=submit name=cancelbtn value=Cancel>";
print " ";
print "<input type=submit name=updatebtn value=Update>";
print "</form>";
echo "<BR>";
} else {
echo "error counter: ", $err_count;
echo "<BR>";
echo "<BR>";
echo "Your data has been updated!";
echo "<BR>";
echo "First Name: ", $new_first_name;
echo "<BR>";
echo "Last Name: ", $new_last_name;
echo "<BR>";
echo "Age: ",$new_age;
echo "<BR>";
echo "His ID number is: ", $id;
}
} else {
Print "No Button Was Pressed";
}
}
?>
any idea how i can do like those forms on the net..
Thanks in advanced.