zoheb Posted April 27, 2010 Share Posted April 27, 2010 well . . hello guyz Can someone temme how to validate table cells ?? . . . ( m using PHP ) I need to validate such tht if no marks are entered for particular sub/term work . . .. an alert box should be popped up thnx in advance . . . Link to comment Share on other sites More sharing options...
0 +theblazingangel MVC Posted April 27, 2010 MVC Share Posted April 27, 2010 It's got nothing to do with 'table cell validation', it's all still form validation, searching google for "table validation" is unlikely to get you results that are as helpful! To display alert boxes you need javascript! You should implement some javascript validation, which will validate the form, display an alert box if necessary, and block/allow the submission of the form as necessary. You should then back up this with server side validation (in your PHP code), because javascript is easy to disable. For PHP validation you will have to make do with outputting the validation errors in your HTML. For javascript validation, you need to add some javascript that captures the submit event of the form and runs a function. The function should refer to each input field in turn, validate there contents, and display an error if necessary. If one or more validation errors occurred, the function will probably need to return false, and otherwise return true; that combined with something like onsubmit="return validateMyForm()" will block/allow the actual submission of the form. You should avoid displaying an individual error message for every field that fails validation - I wouldn't want to click submit on an empty form, and then have to click through 50 alerts to get back to correcting the problem! Link to comment Share on other sites More sharing options...
0 Calculator Posted April 28, 2010 Share Posted April 28, 2010 A good idea would be to combine client-side validation (using JavaScript) with server-side validation (using PHP). When the user clicks the submit button, you can use JavaScript to intercept the click and check for empty fields first. If it finds an empty field, you should prevent the form from being submitted. Even better would be to show an error message (preferably not an alert(), try a paragraph element which appears above the table) and highlight the empty fields (e.g. by making the background color a shade of red to draw the user's attention). When the form is submitted, you should use those same principles for PHP as well. Besides, if a user doesn't have JavaScript enabled and you don't do any server-side validation, you're vulnerable to attacks. If the form is invalid, the table should be outputted again with the same data you received with an added error message. You can list the invalid fields in that error message, or highlight each field individually. Link to comment Share on other sites More sharing options...
0 zoheb Posted April 30, 2010 Author Share Posted April 30, 2010 thnx for ur suggestions . . Link to comment Share on other sites More sharing options...
Question
zoheb
well . . hello guyz
Can someone temme how to validate table cells ?? . . . ( m using PHP )
I need to validate such tht if no marks are entered for particular sub/term work . . .. an alert box should be popped up
thnx in advance . . .
Link to comment
Share on other sites
3 answers to this question
Recommended Posts