Hi all.
I have this site I am trying to make for taking exams/quizzes. I found a program called Learnloop and I am working very hard to try and modify it (knowing very little PHP).
What I need is a way to stop the user from pressing submit more than once and to stop them from going back.
Now the submit once I know I can do with Javascript, but the from already has an onSubmit. I tried to combine the 2 with no luck.
Here is the quiz code (with some irrelevant sections missing). Maybe that can help someone to give me a clue as to what I can do...
I will be ever so happy if you can help!!!
PHP Code:<?require ("../include/global_login.php");
/*************************************************************
Filename: form.php
This is the form that actually displays the questions
to the user. Included in (called from) index.php
**************************************************************/
$GetQ=mysql_query("SELECT question,checkbox FROM questions WHERE id=$question_nr;");
$question=mysql_result($GetQ,0,"question");
$checkbox=mysql_result($GetQ,0,"checkbox");
$CheckDisplayType = mysql_query("SELECT oneOrMany,validation,quiztype FROM quiz_prefs WHERE modules=$modules;");
if($display_row=mysql_fetch_array($CheckDisplayType)){
$oneOrMany=$display_row["oneOrMany"];
$validation=$display_row["validation"];
$quiztype=$display_row["quiztype"];
$countCorrect = mysql_query("SELECT count(correct) AS corrCount FROM answers WHERE correct = 1 AND questions=$question_nr AND active=1;");
$countAnswers = mysql_query("SELECT count(answers) AS answerCount FROM answers WHERE questions=$question_nr AND active=1;");
if($quiztype==1){
if($checkbox==0){
$displaytype="radio";
}else{
$displaytype="checkbox";
}
}else{
if($oneOrMany==1){
if($corr_row=mysql_fetch_array($countCorrect)){
if($corr_row["corrCount"] >1){
$displaytype = "checkbox";
}else{
$displaytype = "radio";
}
}
}else{
$displaytype = "checkbox";
}
}//end if quiztype
}else{
$displaytype = "checkbox";
}
if(mysql_num_rows($countAnswers)==0){
$displaytype = "text";
}else{
if(mysql_result($countAnswers,0,"answerCount") ==0){
$displaytype = "text";
}
}?>
<html>
<head>
<META name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Postural Bodywork | Online Courses for Continuing Education</title>
//style sheet goes here//
<SCRIPT LANGUAGE="JavaScript1.1" src="form.js"></SCRIPT>
</head>
<body bgcolor="#FFFFFF">
<table width="100%" border="0" align="center" cellpadding="6" cellspacing="6">
<tr>
<td>
<b>Question <? echo $Cnt ?></b>
<BR><BR>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
//HERE'S THE ONSUBMIT I WAS TALKING ABOUT...//
<form method="POST" action="answer.php" name="question" onSubmit="return verify(this,'<?echo $validation ?>','<?echo $displaytype?>');">
</td>
<td><b><?echo $question ?></b><BR><BR></td>
</tr>
</table>
<? if($displaytype=="text"){?>
<textarea name="textanswer" cols="50" rows="6" wrap="VIRTUAL"></textarea>
<input type="Hidden" name="quiz_textanswer" value="1">
<?}else{
$alt = mysql_query("SELECT id,answers FROM answers WHERE questions=$question_nr AND active=1;");?>
<table border="0" cellpadding="2" cellspacing="0">
<? while($alt_row=mysql_fetch_array($alt)){
//***********************************************
//All the alternatives are written out
//***********************************************?>
<tr>
<td valign="top"><input type="<?echo $displaytype ?>" value="<?echo $alt_row["id"] ?> " name="alt_id[]"> </td>
<td align="left"><?echo $alt_row["answers"] ?><BR></td>
</tr>
<?}
if ($lead>0){
$CheckLead = mysql_query("SELECT lead FROM leads WHERE questions=$question_nr;");
if($getlead=mysql_fetch_array($CheckLead)){
?>
<tr>
<td> </td>
<td><?echo $getlead["lead"] ?></td>
</tr>
<?}
}?>
</table>
<p>
<?}?>
<input type="Hidden" name="tried" value="<?echo $tried ?>">
<input type="Hidden" name="occ" value="<?echo $occ ?>">
<input type="Hidden" name="Cnt" value="<?echo $Cnt ?>">
<input type="Hidden" name="lasterror" value="<?echo $lasterror ?>">
<input type="Hidden" name="question_nr" value="<?echo $question_nr ?>">
<input type="Hidden" name="modules" value="<?echo $modules ?>">
<input type="image" value="Submit your answer" name="B1" src="../images/submit_button.gif" border="0" width="71" height="21" alt="Submit Answer">
</form>
</td>
</tr>
</table>
</body>
</html>
//HERES THE JAVASCRIPT//
<!--
function cont(m,cnt,occ,view,l){
linkstring="index.php?modules=" + m + "&lead=0&lasterror=1&Cnt=" + cnt + "&occ=" + occ + "&view=" + view + "&last=" + l;
window.location=linkstring;
}
//Check for empty values and display validation alert
function verify(f,validation,displaytype){
var msg;
var checkError = "";
var nr = 0; //Number of alternatives in question
var answer=false; //If user didn't select any alternative
if(displaytype!="text"){
for(i=0;i<f.length;i++){
if((f.elements[i].type=="checkbox") || (f.elements[i].type=="radio")){
nr++;
if(f.elements[i].checked){
answer = true; //User selected at least one alternative
}
}
}
if (!answer){
checkError += "\n- Please select an answer.";
}
}
// If user didn't submit any question or corect answer
// a message should be displayed to the user
if (!checkError) {
if (!validation == "")
return confirm(validation);
else
return true;
}
msg = "______________________________________________________\n\n"
msg += " Please correct the following errors and try again.\n";
msg += "______________________________________________________\n\n"
msg += checkError;
alert(msg);
return false;
}
//-->
Any ideas would be greatly appreciated. I am a beginner at PHP and even moreso at Javascript.
Thanks!!
AManda




The only thing I have been able to get to work using sessions is Kevin Yanks tutorial and that doesnt really help me here...
Try this:



Bookmarks