Simple Moodle Form

Simple Moodle Form

by Sanjeewanie Senanayake -
Number of replies: 4

Dear All,

I'm a research student and very new to Moodle development. I have a problem in creating a simple Moodle form as a plugin. Currently I'm using Moodle 3.1 version. In a Moodle form, I have added a label called 'Name', a text box to enter the name, a 'Submit' button and a 'Cancel' button. My requirement is to store the entered name in a Moodle table and to display it in another page when I click on Submit button. But, always when I click on either 'Submit' button or 'Cancel' button, it displays an error with a 'Continue' button.

I'm very much thankful if anyone can explain me the steps to create that simple form...  

Average of ratings: Useful (1)
In reply to Sanjeewanie Senanayake

Re: Simple Moodle Form

by Jens Eeckhout -

Hi Sanjeewanie,

Could you post the code that generates your form, as well as the error you're getting when clicking the buttons? It's hard to help without more information.

In reply to Jens Eeckhout

Re: Simple Moodle Form

by Sanjeewanie Senanayake -

Hi Jens,

Thank you for your consideration on my question. I have attached my view.php file, the form and the error message. When I click on Save changes button and Cancel button, it gives the same error.

Attachment Error.PNG
Attachment Form.PNG
In reply to Sanjeewanie Senanayake

Re: Simple Moodle Form

by Jens Eeckhout -

Hi,

The "id" parameter is not present when you submit or cancel the form, so your script calls the "error" function on line 48. However, this function is deprecated since Moodle 2.0. You should use the "print_error()" function instead.

In this case, your script will not even get to the part where you process the form, it will only work when you have the "id" or "n" parameter.

Hope this helps. If not, feel free to ask for more info.

Average of ratings: Useful (2)
In reply to Jens Eeckhout

Re: Simple Moodle Form

by Sanjeewanie Senanayake -

Hi Jens,

Thank you very much for your prompt reply. It was really helpful for me to figure out the error. I passed the ID with the form. Now I can view the Success message without any error when I click on the 'Save Changes' button. Thank you again. I will let you know if I face any issue in future.