TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-16-2008, 10:05 PM   #1 (permalink)
The Acquainted
 
buildakicker's Avatar
 
Join Date: Jan 2008
Posts: 119
Thanks: 21
buildakicker is on a distinguished road
Confused JS Effect on error with PHP

HI all,

I am working on a form that I would like to be able to show errors on. Say for example they don't fill in the correct answer in one Input... when they click Submit, I run PHP to get $_Post and then if there is an error I catch it and tell them. Right now I tell them at the top of the page, however, I would like to highlight the inputbox or even the div where the error occered. In PHP do I catch all the problems and store them in vars then display them in a form rewritten? Can I use JS such as the Prototype library to SHAKE the incorrect answer area?

Thanks for any advice or help!
__________________
SkiLeases.com
buildakicker is offline  
Reply With Quote
Old 05-17-2008, 01:37 AM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

No, what you want to do is use JavaScript and the DOM to evaluate that input before the form is submitted, possibly even as they are typing. If there are errors, use the JS DOM functions to manipulate elements on the page, show error messages, etc. Then if the form values are acceptable, allow the form to be submitted to the PHP script handling the input and check the values again. This ensures the user doesn't 'get around' your client side validation by disabling JavaScript. For those that do have JS enabled, their experience is much easier and doesn't require a page load just to check for valid input.

I don't know if 'shaking' the field is a great idea, I tend to avoid all the fancy animations these frameworks allow. Your web application should degrade gracefully and work identically for those users that have JS disabled, have an older or different browser, etc. So giving the user feedback on what's wrong with their input can be identical whether done via JS or PHP.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 05-19-2008, 04:15 PM   #3 (permalink)
The Acquainted
 
buildakicker's Avatar
 
Join Date: Jan 2008
Posts: 119
Thanks: 21
buildakicker is on a distinguished road
Default

Thanks for the reply. Since JS might not function on all browswers, shouldn't I just go about this with PHP errors and leave JS behind?

Thanks!
__________________
SkiLeases.com
buildakicker is offline  
Reply With Quote
Old 05-20-2008, 03:34 AM   #4 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

I have to say, that doesn't make alot of sense. You're concerned that the user is either using an outdated browser or has JavaScript disabled, but you want to use Prototype to create some effects after the fact. It's somewhat of a catch-22.

If you have even a basic client side validation in place, it can catch most problems before submission. The odds that your user base is using updated browsers and have JavaScript enabled I'm sure greatly outweighs the opposite. The only caveat, as I mentioned previously, is to never rely on JS alone but have an even better validation method on the server.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Old 05-21-2008, 04:57 AM   #5 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

question regarding the server side validater.

lets say if js is disabled for a user and they go ahead and fill out the form and submit the page and i have a die or exit function that dies and displays them a message of what they mistyped or something. is there a better way to represent the data rather than showing them a blank white page with a die message?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-21-2008, 05:41 AM   #6 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

sarmenhb> You shouldn't kill the script and just show the user a blank page, your script should handle errors and bad data gracefully. If your script incorporates the user entry form, then add some logic that still shows the form but displays a relevant error that they can correct. If the script is separate and simply handles the input, use a header() call to redirect back to the form page, passing an error handling action in the URL query string.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:08 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design