International Developer Logo Last Updated 19.11.08 at 11.48
 
TUTORIALS

Online Course Management with Moodle


  05.10.06

Now, all that we need to do is create a process.php page to evaluate the form fields and create a new record in the submissions table. By comparing the three image locations, we create a comma delimited list of the submitted image order and compare this with the correct answer. An exact match scores a pass and an incorrect match scores a fail. Here is the snippet from the process page.

 

    require_once(“../../config.php”);

    require_once(“lib.php”);

 

    //get module record

    $ddid  = optional_param(‘ddid’, 0, PARAM_INT);  // draganddrop ID

    $draganddrop = get_record(“draganddrop”, “id”, $ddid);

   

    //get result

    $arrResult = array(

“1”=>$_POST[‘image1’],

“2”=>$_POST[‘image2’],

“3”=>$_POST[‘image3’]

);

    asort($arrResult);

    $result = join(“,”,array_keys($arrResult));

 

    $pass = false;

 

    switch ($result){

      case ($draganddrop->answer);

        $pass = true;

    }

 

In this code you can see that we retrieve the drag and drop module record and compare the correct answer with the submitted answer. After the result has been determined, all that is left to do is insert a submission record and redirect the user accordingly. To create a new submission in the database, another library function is required in lib.php:

 

function draganddrop_savesubmission($submission){

    $submission->timecreated  = time();

    $insert_id = insert_record(“draganddrop_submissions”, $submission);

    return $insert_id;

}




   Previous Page  1 2 3 4 5 6 7 8 9 10 ... Next Page   

HAVE YOUR SAY
This article is rated  Rate this article