SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast AmandaArias's Avatar
    Join Date
    Sep 2001
    Location
    Houston, TX USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please Help. Im Desperate~

    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[]">&nbsp;&nbsp;&nbsp;</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>&nbsp;</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

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you just use the setcookie() function in PHP and redirect to a different page if the cookie has been set?

    Sketch
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Enthusiast AmandaArias's Avatar
    Join Date
    Sep 2001
    Location
    Houston, TX USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Because I am dumb and I dont know how...

    See. Here is my problem.. I have to see the code in order to learn to do it.. Someone literally has to give me a live working full version code before I understand how it all comes together and works. I have been trying to learn cookies and sessions for the past 2 days, but as I said before.. I am dumb. Maybe you could post an example and I can go from there.. or maybe I am asking too much. I know this is gonna come back on me and someone is gonna say.. go read the manual.. Well, I have.. Please help. The only thing I have been able to get to work using sessions is Kevin Yanks tutorial and that doesnt really help me here...

    Amanda

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand. Try this:
    PHP Code:
    if(isset($cookie))
    {
      
    header("Location: [b]page you want to send user to if cookie is set[/b]");
      exit();
    }
    else
    {
      
    $future mktime("0","0","0","7","15","2002"); //expiration time format is Hour, Minute, Second,Month,Day, Year
      
    $time_till $future time();
      
    setcookie("cookie","1",time() + $time_till);

    Does this make sense?
    Sketch
    Last edited by Sketch; Nov 8, 2001 at 20:52.
    Aaron Brazell
    Technosailor



  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course, that won't work for anyone that has cookies disabled.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    true...serves 'em right!
    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Enthusiast AmandaArias's Avatar
    Join Date
    Sep 2001
    Location
    Houston, TX USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any ideas Mr Pepper?

    I would love to hear any ideas you have since you helped me last time I had a problemo!!

    ~Amanda

  8. #8
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you aren't going to be able to stop people from going back, i don't think. about the only thing you can do is what Sketch said -- use cookies. just looking at his code, it doesn't look like it will work right. it would ALWAYS redirect to another page just b/c the cookie is set -- even if they're on the right question, as the cookie would be present from the previous question.

    why are you wanting to prevent them from going back? so that they can't go change their answer i assume? i don't have time to figure out exactly how to implement this and where to put the code for ya, but i can tell how i would TRY to do it. and it isn't very good.

    each time a question loads, set a cookie called "question" and set the value to the number of the current question. and you would also check the value of the "question" cookie, and if it's greater than the question they're trying to load, you'd know they went back and could take some action -- like redirecting to another page as Sketch showed. the problem with redirecting to another page is, how are they going to get to the question that they're supposed to be on w/o going to a previous question, and consequently continue to be redirected? the best way would be to look at that "question" cookie and load the question that they're supposed to be on regardless of which question they're actually trying to load. ugh, messy! and of course none of this would work for people that have cookies disabled -- unless you MAKE them have cookies on before they can take the test.

    sorry i'm not more help.
    Last edited by DR_LaRRY_PEpPeR; Nov 9, 2001 at 17:05.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •