Cant add the HTML Forms in moodle

Cant add the HTML Forms in moodle

by Ashutosh Bhardwaj -
Number of replies: 12

It could be very simple,

Have been trying to insert an html form snippet on frontpage.  Added a custom HTML Block, Went to configure screen - Provided the html snippet in Editor. 


But Once i press save, the  <form> TAG is being stripped off.  sad


I tried many times, All other elements rendered fine. 

I have a fresh installed latest moodle, latest essential theme for moodle 2.8. 


Is there any solution to this ? I really like the ability to edit the HTML Block from moodle admin, hence adding snippet to the file will be my last choice. 

Alternatively, if the adding via HTML Block not possible, is there a way i can create an altogether seprate block "myform block" and then  will be able to select that block from Add to block dropwon section on frontpage


What are your thoughts?? Any clue ?? 


Thanks


Average of ratings: -
In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Brian Barnes -

Hi Ashutosh,

Why do you want a form in an HTML block? Chances are that Moodle will not be able to process it correctly anyway (session keys are required for most form submits for security reasons, and there is no way that you can get the session key in the HTML block). Although I haven't looked into this directly, I would imagine that there are a number of tags that will be removed (<script> being another) for security reasons.

Your best bet is to create your own block plugin - see https://docs.moodle.org/dev/Blocks and https://docs.moodle.org/dev/Blocks_Advanced for more information.


Cheers,

Brian Barnes

In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Tell us a bit more about what you are trying to do.  The editor strips out all sorts of tags. 

If you are trying to add a mailing list sign up form or survey of some sort, there might already be a plugin for that. If there is nothing that works for you,

i)  make your own plugin

or

ii) if you just need to collect data, use the Database activity or see the Dataform module. Perhaps place a link to one of those activities in the html block.

or

iii) add your form as a template with the Generico filter, then add that to the html block.

In reply to Justin Hunt

Re: Cant add the HTML Forms in moodle

by Ashutosh Bhardwaj -

Thank you guys but this is getting too complex. 

I Mean just to add a form, I Would have to develop a whole new plugin. This is frustating.


My need is very simple, I would like to add a simple html form (kind of a poll form with check box buttons) on frontpage and default homepage (my/indexsys.php)


Isn't there any template php file where i can directly insert that html code with form tags? So that i can get rid of the blocks, and I can just have hard coded form area on my favourate place and i can dow whatever i want with it?? 


Any pointer?? Also where can i find the list of php files responsible for display of each type of page like homepage, courses page for learners etc.


I just need a fine and easy control over the UI of moodle.

Thanks

In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

"I just need a fine and easy control over the UI of moodle."

To do that requires learning how Moodle works, in a similar way it would if you were customising Wordpress, Drupal or similar tools.  I recommend customising an existing block to learn how it works. You can find the developer documentation here

http://dev.moodle.org/


Average of ratings: Useful (1)
In reply to Marcus Green

Re: Cant add the HTML Forms in moodle

by Ashutosh Bhardwaj -

Agreed.

I could customize wordpress to a great extent, and if i'm stuck I can just go straight into template.php files and put my code there. 

This is how simple things can be quickly achieved, instead revolving around the complex approach that are very slow and yet does not produce much user friendly output.

In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
In reply to Richard Oelmann

Re: Cant add the HTML Forms in moodle

by Ashutosh Bhardwaj -

Thank You. Already tried that.

It does not work in moodle 2.8 (gives errors while creating polls etc - Context does not belong to any course

Do you have any pointers to fix this? Thanks
In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by M Williams -

Hi, 

I've needed to do this on some pages, where there are form elements on the page which allow a user to mark true or false with radio buttons and then un-hide a <div></div> with the answer. I've also used it for textareas, so the user adds their answers and then reveal the teacher answers. The form doesn't do anything , as in post the form anywhere. 


Composition is thus:

<form action="">

*All sorts of html form elements here*

</form>

Not sure if that's what you're looking for but it's been a solution to our needs. 


In reply to M Williams

Re: Cant add the HTML Forms in moodle

by Ashutosh Bhardwaj -
Hi, Agree.

That is the simplest solution, and was my first try as well. However moodle striped the form tags from HTML Block. So cannot submit form sad


Also I Like the Poll Block functionality, however its a bit buggy for 2.8, so I'm looking either for a patch or suggestion to make it work smile 

In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Darko Miletić -
There is no "simple way" of doing this. You need a form in a block? You need to write your own block plugin and code it to display whatever you need. It sucks, I know but that is the way things are with Moodle.
Average of ratings: Useful (1)
In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by William Lu -
Picture of Particularly helpful Moodlers

In an editor, <form> </form> will be stripped off anyway.

You can:

1. Try to compromise your form to suit the available fields of Feedback, Questionnaire plugs or Database.

2. Use Justin's Generico plugin (Very powerfull)

3. Create your form in a stand alone HTML page and upload it as File (add a resources). You can create other form pages like thankyou.html etc in the same File resources and only set the form.html as the Main file.

HTH

In reply to Ashutosh Bhardwaj

Re: Cant add the HTML Forms in moodle

by Ken Task -
Picture of Particularly helpful Moodlers

Sometimes, it's just best to seek a solution that can appear to be part of Moodle, but isn't.

Check out: http://www.appnitro.com/

Can't actually take credit for discovering ... server admin before me did.   Is commercial.  On Moodle site where it's used, it resides/installs in a 'forms' directory among the same folders for Moodle.  One can git update the Moodle with no problems but if upgrading the old way, one will have to make sure to move the forms folder into the new code for Moodle.

Has separate backend DB, administration, users, etc.. directly accessible via URL, but the interesting feature is the ability to use forms embedded into other applications (such as Moodle).  It provides an 'embed' URL for each form you build for the site.   In Moodle, one uses simple embedding code which MachForm provides.

One could also do the same thing with Google Docs/Forms.

For info:

http://www.eclass4learning.com/embed-google-form-moodle/

YouTube Video:

Neither one, however, will tie into Moodle code/backend DB etc.. ... at least not without some special programming in Moodle.  But maybe that's really not needed.

'spirit of sharing', Ken

Average of ratings: Useful (1)