diff --git a/lib.php b/lib.php
index 390d9c489fe8719e8f3fab3661fb17b0c6d1e07f..a9b3856a3baa8b5c7ba01f2802f5af3711daa0a5 100644
--- a/lib.php
+++ b/lib.php
@@ -30,7 +30,7 @@ require_once($CFG->dirroot . '/lib/oauthlib.php');
  * Use lti to login and retrieve cookie from opencast.
  */
 function filter_opencast_login() {
-    global $CFG, $PAGE, $COURSE, $USER;
+    global $PAGE;
 
     // Get api url of opencast.
     $endpoint = get_config('tool_opencast', 'apiurl');
@@ -39,6 +39,20 @@ function filter_opencast_login() {
     }
     $endpoint .= '/lti';
 
+    // Create parameters.
+    $params = filter_opencast_create_parameters($endpoint);
+
+    // Render form.
+    $renderer = $PAGE->get_renderer('filter_opencast');
+    echo $renderer->render_player($endpoint, $params);
+
+    // Submit form.
+    $PAGE->requires->js_call_amd('filter_opencast/form', 'init');
+}
+
+function filter_opencast_create_parameters() {
+    global $CFG, $COURSE, $USER;
+
     // Get consumerkey and consumersecret.
     $consumerkey = get_config('filter_opencast', 'consumerkey');
     $consumersecret = get_config('filter_opencast', 'consumersecret');
@@ -57,7 +71,7 @@ function filter_opencast_login() {
     $params['context_id'] = $COURSE->id;
     $params['context_label'] = trim($COURSE->shortname);
     $params['context_title'] = trim($COURSE->fullname);
-    $params['resource_link_id'] = 'o' . random_int(1000,9999) . '-' . random_int(1000,9999);
+    $params['resource_link_id'] = 'o' . random_int(1000, 9999) . '-' . random_int(1000, 9999);
     $params['resource_link_title'] = 'Opencast';
     $params['context_type'] = ($COURSE->format == 'site') ? 'Group' : 'CourseSection';
     $params['lis_person_name_given'] = $USER->firstname;
@@ -85,21 +99,5 @@ function filter_opencast_login() {
     $params['oauth_signature_method'] = 'HMAC-SHA1';
     $params['oauth_signature'] = $helper->sign("POST", $endpoint, $params, $consumersecret . '&');
 
-    $content = "<form action=\"" . urlencode($endpoint) .
-        "\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
-
-    // Construct html form for the launch parameters.
-    foreach ($params as $key => $value) {
-        $key = htmlspecialchars($key);
-        $value = htmlspecialchars($value);
-        $content .= "<input type=\"hidden\" name=\"{$key}\"";
-        $content .= " value=\"";
-        $content .= $value;
-        $content .= "\"/>\n";
-    }
-    $content .= "</form>\n";
-
-    echo $content;
-    // Submit form.
-    $PAGE->requires->js_call_amd('filter_opencast/form', 'init');
+    return $params;
 }
\ No newline at end of file
diff --git a/renderer.php b/renderer.php
index f0d0c5926e25d41037f6e38774523417546aecaa..c5cb58df3c319a5d49ffe12d4ca637c26bb40a9a 100644
--- a/renderer.php
+++ b/renderer.php
@@ -45,4 +45,28 @@ class filter_opencast_renderer extends plugin_renderer_base {
     public function render_player($data) {
         return $this->render_from_template('filter_opencast/player', $data);
     }
+
+    /**
+     * Display the lti form.
+     *
+     * @param object $data The prepared variables.
+     * @return string
+     */
+    public function render_lti_form($endpoint, $params) {
+        $content = "<form action=\"" . urlencode($endpoint) .
+            "\" name=\"ltiLaunchForm\" id=\"ltiLaunchForm\" method=\"post\" encType=\"application/x-www-form-urlencoded\">\n";
+
+        // Construct html form for the launch parameters.
+        foreach ($params as $key => $value) {
+            $key = htmlspecialchars($key);
+            $value = htmlspecialchars($value);
+            $content .= "<input type=\"hidden\" name=\"{$key}\"";
+            $content .= " value=\"";
+            $content .= $value;
+            $content .= "\"/>\n";
+        }
+        $content .= "</form>\n";
+
+        return $content;
+    }
 }
\ No newline at end of file