Thanks for reaching out to me and asking your question.
Saving user input to the database is on my TO DO list for features I would like to add to Contact Form for Moodle in the future. It might not be this year as I have other priorities but it is definitely on the roadmap.
If you wanted to create your own right now, I would start by cloning the Contact Form plugin. Then look for the lines that generate the email. Instead of building the email, you would simply write the fields to a database table you created. Take a look at the Moodle data manipulation API for more information on how to do this.
Since the plugin allows any number of fields of any kind to be submitted, I would recommend that each field be added to the table as a new row instead of one row per submission. Naturally you would want to have some identifier to show which rows were part of a specific submission.
On the other hand, if you are only doing this for a single strictly defined set of fields, you could make each submission a separate row. In this case, you would pre-define your fields in the table. Instead of looping through all of the submitted fields, you would require specific fields. With that said, if you are choosing to go down this route, you might want to consider using the Moodle Forms API to collect information and then using the Moodle data manipulation API to write it to the database instead. The only reason Contact doesn't go this route is because it doesn't really lend itself easily to processing forms that can have any number of fields.
One of the strategies I use when creating a new Moodle plugin is to try and find some existing plugin that offers similar type of functionality. For example, in your case, you might want to take a look at how the Moodle Journal activity plugin is made. I haven't looked at it but it sounds like a plugin that has students write a journal entry in a Moodle form and then saves the submitted information into a table in the database.
I haven't really looked into it but have you considered whether the Moodle database activity could be used to achieve what you are trying to do? Feedback could also be an option.
I would need to know more about what you are trying to achieve and your expected outcome in order to narrow down your options.
TIP: Feel free to ask questions in the Moodle Community General Developers forum. There are lots of developers who would also be happy to answer your questions. For best results:
- First see if you can solve problems on your own. Don't be afraid to try things out.
- When you do post a request for help, use a meaningful and relevant subject line (not something like "Help" or "Question for you").
- Explain what you are trying to achieve.
- Describe the challenge you are experiencing.
- Show what you have tried and either include relevant source code (not the whole plugin) or a link to your project on GitHub and a short description of which file/lines the relevant source code is in.
- Explain what you are hoping to achieve.
Take a look at a post called "How to store form data in Moodle database table?" which is a pretty good example. You may also find it relevant to what you are trying to achieve.
Above all, always ask nicely, be patient and show gratitude for any help you get. If the answer was helpful, be sure to rate their post as useful (it is a dropdown at the bottom of their message). Remember, these people are volunteering their time to try and help you.
Thanks again for your great question! You can do this.