Monday, December 12, 2011

Extending the Form Maker

In an earlier post, I introduced the remarkable Form Maker block. The block allowed you to create a data entry form where users could type in data input. The block allows you to output the data in PDF or XLS (Excel) format. Cool! The only problem I faced with it was that it allowed only a maximum of 11 fields. 10 fields plus the default email field. So what happened if you wanted to capture more data with the block? Well, you couldn't because there was no direct way to extend the number of fields beyond the default limit!

Until now. I poked around the code a bit and discovered that you could increase the number of edit fields in the front end by increasing the 10 part of the code to 20, whenever you see the < 10 code in these three files: config_instance.html, block_form_maker.php and block_form_maker_submit.php.

\config_instance.html (2 hits)
Line 61:  for ($i=0; $i < 10; $i++) {
Line 207:  for ($i=0; $i < 10; $i++) {
\block_form_maker.php (1 hit)
Line 44:  for ($i=0; $i < 10; $i++) {
\block_form_maker_submit.php (2 hits)
Line 20:  for ($i=0; $i < 10; $i++) {
Line 46:  for ($i=0; $i < 10; $i++) {

Change those lines to:

\config_instance.html (2 hits)
Line 61: for ($i=0; $i < 20; $i++) {
Line 207: for ($i=0; $i < 20; $i++) {
\block_form_maker.php (1 hit)
Line 44: for ($i=0; $i < 20; $i++) {
\block_form_maker_submit.php (2 hits)
Line 20: for ($i=0; $i < 20; $i++) {
Line 46: for ($i=0; $i < 20; $i++) {

After editing the files, save them back to their original filenames and FTP them back to the block's folder in your production or test site.

However, that's not the end of it. You also need to edit the block_form_maker table and add more fields into it. Whazzat? Don't worry, all you need is to download and install the popular phpMyAdmin tool. Then go to Administration | Server | Database to list the tables of your Moodle database. Like so:

Ratings and Recommendations by outbrain