Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling error message display

Status
Not open for further replies.

RobDar

Technical User
Jan 13, 2006
1
US
I am by no means a PHP wiz...
I am using PHP to validate my submission form on my website and to submit the important info to a flat file.
I cannot seem to get the error messages, thank you messages, and so forth to work in any other way than to the boring old text on a white page. Users then have to click "back" to fix whatever is wrong. I want the errors to show in a pop up, or to reload the form with highlighted area...or on a seperate page...something stylish. Right now when an error occurs or user forgets a required field it goes to a blank page with the error explination...feels like you are being kicked off the site cause you screwed up!

 
First, you need to demystify PHP in your head. PHP can, through print and echo statements, print out any html code you want. Knowing that, it should be easy to just display what you want and however you want it. Now, to look at your situation.

First of all, you need to know that you cannot tell a user they forgot to fill out a field before they submit the page. That kind of validation is done through client side code (primarily javascript) and while benefitial to a lot of users who did not want to reload, it is due to its client side nature not to be fully trusted.

So, you are left with the reloading of the form and pointing out what the user missed. This is best done if the form, the validation and the submission is a single script (one file). It starts with a simple if clause, which checks if the user has already submitted the form. If not, regular empty form is displayed. If yes, the fields are checked. If all the fields are ok, form submits. If not fields that were filled out properly are inserted into their respective input boxes and those which were left out/wrong are pointed out to the user. When user corrects this and submits again, they are taken through the same procedure, so if everything will be ok, the form should submit.

This is a simple explanation of how it should work. It does not require a whole lot of knowledge in PHP, since it is mostly echoing out html and doing simple checks in if sentences. Try working on that and if you run into a specific problem come back here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top