Train-Up!

The de facto e-learning plugin for WordPress

Custom questions

Train-Up! allows developers to create custom questions, other than the standard Single-answer or Multiple-choice style questions.

Questions can be comprised of any web-technology, e.g. Flash or JavaScript, or just some form inputs. All you have to do is:

  • Decide what to save as the users answer
  • Determine what is required for their answer to be correct.

Example

To gain a food hygiene certificate the trainees must prove they know which colour chopping board is appropriate  depending on the food type.

food_question

We recommend studying our add-on questions to see how to you too can create custom questions.

As the developer you just have to make sure that the form data submitted from the above example is stored in the database. Here is how you would do that:

add_filter("tu_save_answer_MyCustomQuestion", function() {
  return $_POST['colours'];
});

add_filter("tu_validate_answer_MyCustomQuestion", function($correct, $answer) {
  return (
    $answer['red'] === 'raw_meat' &&
    $answer['green'] === 'salad_and_fruit' &&
    $answer['yellow'] === 'cooked_meats' &&
    $answer['blue'] === 'raw_fish'
  );
}, 10, 2);

add_filter("tu_render_answers_MyCustomQuestion", function($colours) {
  $view = "<input type=hidden name=colours[red] value={$colours['red']}>";
  // $view .= '...etc...';
  return $view;
}, 10, 1);