Jump to content

[SOLVED] Help: Trying to give a validation WARNING..... Preceed / Cancel?


arsl1006

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. ??

Link to comment
Share on other sites

;D

 

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.