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
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.
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
Re: Loading custom HTML forms and PHP scripts into Moodle
Tim
Re: Loading custom HTML forms and PHP scripts into Moodle
<?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?
Re: Loading custom HTML forms and PHP scripts into Moodle
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.
Re: Loading custom HTML forms and PHP scripts into Moodle
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.
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:
- if you say include('../config.php') require login, if (isteacherinanycourse()) {..} and you only create views on the database by changing "the easter egg code"?
- if you do the same but also store content of self coded form-fields in the database..
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.
Re: Loading custom HTML forms and PHP scripts into Moodle
Having that capability in Moodle would be a very desirable feature.
I hope they will consider it.

Re: Loading custom HTML forms and PHP scripts into Moodle
Re: Loading custom HTML forms and PHP scripts into Moodle
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.