|
Posted by Jerry Stuckle on 11/17/06 19:59
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
==================
Navigation:
[Reply to this message]
|