Text editors

Loading custom HTML forms and PHP scripts into Moodle

 
 
Picture of Jose Hales-Garcia
Loading custom HTML forms and PHP scripts into Moodle
 
I'm not sure this is the best topic area to post these question, but here goes...

I want to be able to put HTML forms inside of Moodle, and I also want to be able to put PHP scripts inside of Moodle. Several questions come to mind:

1) What is the best way of doing this? Do I create them independently of Moodle, on the file system, and to then link to them from Moodle.

2) Can Moodle be used to create and/or manage my HTML forms and PHP scripts? That is, can I upload a PHP script as a file into Moodle and hope it will execute if I link it up in Moodle?

3) Can the HTML editor be used to create html forms?

Thank you in advance,
Jose
 
Average of ratings: -
Picture of Peter DeBruyn
Re: Loading custom HTML forms and PHP scripts into Moodle
 

I create mine using Dreamweaver or phpFormGenerator .   You can link to external HTML and PHP files from anywhere you can put links in Moodle and you might use glossaries, wikis, html blocks, course topic sections, etc... to manage them.  Most of the time I have setup a "resource" and linked to php or html pages.  This allows you to set up a frame for your page and gives the appearance that everything is happening within Moodle including you header and the site breadcrums.

This html editor will not create forms or allow php script as far as I know.

 
Average of ratings: -
Picture of Clarence Prudhoe
Re: Loading custom HTML forms and PHP scripts into Moodle
 

You can use code generated in other editors including forms, PHP, Java script, etc. if you first go to your Moodle configuration/editor settings and change the htmleditor to "do not allow".  Thus, when you edit a page, only the html script editor will open.  You can also enter the html editor then toggle the <> script editor, paste your script, then save the file while you are still in the script editor, but if you open the html editor again, your script will be lost.

Paste only the script that is inside the body (do not use the body tags) into the Moodle script editor then save the page.  Moodle already has the header and body tags built in.

Your imported script should now work.  However if you turn the HTML editor back on and then attempt to edit this page, the Moodle HTML editor will attempt to rewrite your script and it will chew it all up.  I keep a backup copy of the script I enter into Moodle in a WordPad file so I can fix it if I forget and mess up the script by entering the html editor.

I think you will want to leave the htmleditor on for general use but you can turn it off to build special pages.

Let me know if this works for you.

Clarence

 
Average of ratings: -
Me and Ray
Re: Loading custom HTML forms and PHP scripts into Moodle
 
This is amazing. I thought that javascript would be removed as a security precaution whether I used the htmleditor or not. But you are right. It is easy to add javascript just by turning off the html edit at the admin level. I wonder if it is as easy for everyone else to add javascript.

Tim 
 
Average of ratings: -
Picture of Randy Orwin
Re: Loading custom HTML forms and PHP scripts into Moodle
 
This seems to work fine for javascript but I have not been able to get it to work with php scripts.  I have done a bit of php programming but none to speak of in the object oriented way.  I tried just the basic hello world script:

<?php echo "hello world" ?>

and it doesn't show up.  When I view the source of the page it shows up in the source instead of php parsing the script and printing hello world.  Any ideas?
 
Average of ratings: -
Picture of Steve Garcia
Re: Loading custom HTML forms and PHP scripts into Moodle
 
PHP has to be intepreted by Apache.  What you edit in the HTML editor is stored in the database, so by the time Apache sees it, it has already processed all the PHP.
 
Average of ratings: -
Picture of Randy Orwin
Re: Loading custom HTML forms and PHP scripts into Moodle
 
So you are saying that I cannot embed php scripts like you can javascripts?  Even if I could include a php file that would take care of what I need to do.
 
Average of ratings: -
Me and Ray
Re: Loading custom HTML forms and PHP scripts into Moodle
 
Randy
I think that you would need to hack moodle to add php. If you can write php then it should not be so difficult for you to add some php into the relevant part of moodle.
 
Average of ratings: -
Picture of Randy Orwin
Re: Loading custom HTML forms and PHP scripts into Moodle
 
I thought that may be the case.  I wrote a small cms for the public relations person in our district a couple of years ago so she could post items to the front page of our current web site based on a go live date and an expire date.  She can create 3 different types of articles, standard, emergency and a quick link that shows up in a box on the right side of the page, set a go live date and an expire date and the server takes care of the rest. 

I was hoping to just use an include statement to make the database queries and load it to the site home page in Moodle.  We are seriously looking at using Moodle for our basic web services as well as all the other cool course management features for teachers.

As I get better at the object oriented approach of Moodle maybe I will look at writing a course format that will do the kinds of things I am looking for.
 
Average of ratings: -
Picture of Ger Tielemans
Re: Loading custom HTML forms and PHP scripts into Moodle
 

But even if you create your own pages in PHP and add them with ftp to the moodle dirs, how secure are you if:

  1. if you say include('../config.php') require login, if (isteacherinanycourse()) {..} and you only create views on the database by changing "the easter egg code"?
  2. if you do the same but also store content of self coded form-fields in the database..
 
Average of ratings: -
Picture of Steve Garcia
Re: Loading custom HTML forms and PHP scripts into Moodle
 
Javascript runs in the browser at the users end.  At the time you generate it it (as Moodle reads it from the database) the user's instance of the browser has not yet seen it, so what you have prepared to display in her browser is still malleable.

PHP runs at the server end.  At the time that Moodle pulls up your code from the database, Apache has already interpreted all the PHP code, so no, it is not possible to embed PHP from within Moodle.  If the HTML editor were set up to edit files on the server from within Moodle, then you could do something like this.

But you wouldn't want to.  This would not be a small security hole, this would be a HUGE one.
 
Average of ratings: -
Dallas Ray Smetter
Re: Loading custom HTML forms and PHP scripts into Moodle
Group Moodle Course Creator Certificate holders
I use embedded PHP within Drupal quite often. That particular CMS allows users with the appropriate permissions to do so.

Having that capability in Moodle would be a very desirable feature.

I hope they will consider it. big grin
 
Average of ratings: -
Picture of Leopoldo Sanczyk
Re: Loading custom HTML forms and PHP scripts into Moodle
 
I'd like it too! sonrisa
 
Average of ratings: -
Picture of Mauno Korpelainen
Re: Loading custom HTML forms and PHP scripts into Moodle
Group Particularly helpful Moodlers

For "normal use" of administrators and teachers the old trick is to use iframe tags. Embed the php script (or a web page using php) with tags like
<iframe src="path to your script" width="100%" height="580"></iframe>

Scripts inside iframe can also discuss with moodle - for example editor itself and most popups are just sending data (variables) between iframes or javascript windows and php files of moodle.

By default iframe tags are not allowed in such activities that students can use (user profile, forums,...) but IF you want to allow use of iframe tags (and php inside iframe) for students too you may add <iframe> to the list of allowed tags $ALLOWED_TAGS in lib/weblib.php

Tweaks like http://moodle.org/mod/forum/discuss.php?d=97830 are also possible but keep in mind that every user php script can be malicious and insecure php code is very simple to be hacked.

 
Average of ratings: -