arsl1006 Posted July 16, 2007 Share Posted July 16, 2007 I was hoping one of you nice people could help me. I'm new to PHP (and web based programming in general); however, I’m developing a web-based questionnaire that records the results into a MySQL database. The questionnaire is, in the main part (and somehow?) working, however, I'm having problems with part of the validation. Where the validation rule-rules something is missing where it MUST be present, the validation works... i.e. your redirected back to re-enter the data and the PHP quits. Where I’m having problems is - I’m required to ask the user, if some of the questions are unanswered, if he/she is aware of it and would like to continue with the submission OR if they would like to finish the questions? I gather with PHP there is no use of windows messages boxes (due to being platform independent), so... I'm lost. Can anybody help or point me to a suitable article. I've been scanning the web for hours now and not having much luck. If doesn't need to be a message box, just somehow give the user the option. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 16, 2007 Share Posted July 16, 2007 run a query to see if the user has answered all the questions and put the query in a variable. and make a if statement and else statement. $answers being how many they answered, and $questions being how many questions their is. <?php if($answers==$questions) { echo("Good Work Completing the Quiz"); } elseif($answers!==$questions) { echo("You still have questions to answer, go back"); } ?> or instead of go back, display links to the questions they missed. Regards ACE Quote Link to comment Share on other sites More sharing options...
arsl1006 Posted July 16, 2007 Author Share Posted July 16, 2007 Thankyou for your prompt reply. This form of validation i have working fine. The problem i have is when i get to the point: echo("You still have questions to answer, go back"); I need to provide the options of continuing with unanswered questions OR returning to the questions to complete the remaining questions. ?? Quote Link to comment Share on other sites More sharing options...
arsl1006 Posted July 16, 2007 Author Share Posted July 16, 2007 Solved the problem... I think it's the best way forward unless anyone can point out otherwise… It seems to me that validating the form client-side (using JavaScript) is the most straightforward way to validate forms. +Plus JavaScript allows the use of the alert (Message Box) function - very useful when highlighting errors. I guess in some cases validation must be done server side, but would people recommend doing as much validation as possible client side? Quote Link to comment Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 but would people recommend doing as much validation as possible client side? Yes. But you should also validate server side especially prior to any database inserts. Client side is great as it can give the client an instant response, however, javascript can be disabled / worked around. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.