diff --git a/amd/src/form.js b/amd/src/form.js
index adb0e42b9e982af12fd6d76101ce8eabab246278..2baaa55694b9effa4369daefaf3c7885da6a0007 100644
--- a/amd/src/form.js
+++ b/amd/src/form.js
@@ -21,17 +21,19 @@
  * @copyright  2018 Tamara Gunkel
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-define(['jquery'], function ($) {
+define(['jquery'], function($) {
 
     var t = {
         /*
          * Submits lti form and updates the source attribute of the video iframes
          */
-        init: function () {
-            $('#ltiLaunchForm').submit(function (e) {
+        init: function() {
+            $('#ltiLaunchForm').submit(function(e) {
                 e.preventDefault();
+                var ocurl = decodeURIComponent($(this).attr("action"));
+
                 $.ajax({
-                    url: 'http://localhost:8080/lti',
+                    url: ocurl,
                     crossDomain: true,
                     type: 'post',
                     xhrFields: {withCredentials: true},
diff --git a/lib.php b/lib.php
index 2cf9b0b9dea85c9f5b081461befa13d5c083c0c5..ce23b448dc4aa2363beb1b0eea89b4d7205ac13d 100644
--- a/lib.php
+++ b/lib.php
@@ -85,7 +85,7 @@ function filter_opencast_login() {
     $params['oauth_signature_method'] = 'HMAC-SHA1';
     $params['oauth_signature'] = $helper->sign("POST", $endpoint, $params, $consumersecret . '&');
 
-    $content = "<form action=\"" . $endpoint .
+    $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.