Wednesday, May 19, 2010

Log directly into a moodle course from an external domain

I have been searching the moodle forums for this for about 2 months now. Sometimes I would find a nice short answer like "it cant be done". Sometimes there would be a fairly complicated solution, and sometimes a nice easy one, but in either case it didn't work on my, fairly vanilla installation.

The problem I was trying to overcome was this. I wanted to create an external for to my moodle course. Once the user has filled in the form, they should be taken straight to the course, not to be given another link to the course.

Here is how to do it, simply.
The login page should have something like this in it.

<form action="http://yoursite.com/exactLocationYouWantTheUserToArriveAt" method="post">
<fieldset>
<label for="username">Username:</label>
<input id="username" name="username" type="text" />
<label for="password">Password:</label>
<input id="password" name="password" type="password" />
</fieldset>
<fieldset><input type="submit" value="Login" /></fieldset>
</form>

Then you want to look for the directory of the theme you are using for your moodle course. In there you will find a file called header.html which you need to edit.
As the first item of JavaScript, just below the meta tags, you need to apply code like the one below.
<script type="text/javascript">
var str = document.referrer;
if(str.substring(7,25)=="domainOfTheExternalForm.com")
{
window.location = "/exactLocationYouWantTheUserToArriveAt";
}
</script>

This should take you from a form on an external to the course of your choice.

No comments:

Post a Comment