|
Posted by Jerim79 on 11/17/06 20:17
Jerry Stuckle wrote:
> Jerim79 wrote:
> > e_matthes@hotmail.com wrote:
> >
> >>>It can still be conditional. Put it at the top, and if everything is
> >>>OK, just have it fall through to the HTML.
> >>>
> >>>BTW - this is a very user-unfriendly way of doing it. You should rather
> >>>check all the options, then if any are incorrect, redirect with all of
> >>>the invalid information. This way if there are three things wrong, the
> >>>user must gets an error message for the first one and corrects it. Then
> >>>he gets an error message for the second one, and so on.
> >>>
> >>>If you check them all, you can display all three error messages at the
> >>>same time. Much more user friendly.
> >>
> >>Something like this, I believe:
> >>
> >><?php
> >>
> >> // Code to check validity of data.
> >>
> >> if (everything valid) {
> >> // code to process data
> >> // redirect to new page
> >> } else {
> >> // Set error messages for individual data elements.
> >> }
> >>
> >>?>
> >>
> >><html>
> >>
> >> <form>
> >> <input 1>
> >> <?php if ($errorMsg1 != "") print $errorMsg1 ?>
> >> <input 2>
> >> <?php if ($errorMsg2 != "") print $errorMsg2 ?>
> >> ...
> >>
> >></html>
> >
> >
> > I appreciate the help. I think the concept is getting clearer. I am
> > just curious though. The first time a person loads the webpage wouldn't
> > the php execute and since all of the variables are null, wouldn't it
> > automatically display an error message even before the person has had a
> > chance to fill out the form?
> >
>
> If you're validating on the same page, yes. You have to test for that.
>
> For instance, if you have your submit button as:
>
> <input type="submit" name="submit" value="Submit">
>
> you could check:
>
> if (isset[$_POST['submit'] && $_POST['submit'] == 'Submit') {
> ... do your validation here
>
> Just be sure no other page posts to this one with the same submit button.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================
Here is the basic gist of what I have:
<?php
$FName=$_Post['FName'];
if ($FName !=""){
header("Location: write_to_database.php");
}
else{
if ($FName=""){
$errormsg1="Please enter a first name":
}
?>
<html>
<body>
Registration
<?php if ($errormsg1 !="") echo $errormsg1); ?>
<br />
<form action="(this page)" method="Post">
First Name: <input type="text" name="FName">
<br />
<input type="submit" name="submit value="Submit">
</form>
</body>
</html>
Forgetting the problem about loading the errors up before filling out
the form, I can't get this to work at all. After I click on submit it
just brings me back to the same page, with no error messages.
[Back to original message]
|