Pages

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:





Once phpMyAdmin window opens, navigate to the block_form_maker tables.


Click on the table.You should be able to see the innards (fields) of the table.


Well if you observe carefully, you will see that there are a maximum of 11 fields with the default version of this block. So how do you insert another field inside the table? See the image below!



Select field9 from the dropdown (dropup?) list and click the 'Go' button.

Type the name field10 in the Field edit box. Select longtext for Type, utf8_general_ci for Collation, null for Null and NULL for Default. Then click the Save button.


You will notice that there is a new field named field10! So I suppose you could repeat the last few steps another 10 times or more if you wanted to add more fields. But there is a 'short-cut'.


See the image above.
Type 5 inside the Add editbox, click on the After radio button and then click the Go button!


Type the field names and settings as shown below.


Click the Save button. You will see your newly added fields in the list.


Close the window and return back to youe Moodle homepage or coursepage. Now all you need to do is to add a new Form Maker block and then edit its settings (click on the Moodle Edit button of the block):



Type in the field names ...

... and then click Save Changes.


There you go, a form with 17 fields, all ready to be typed in.

So now you know. That's all!

If you like this post or site
a small donation would be nice but would last only a day,
otherwise leaving a comment (or a compliment) below will last me a month!

Ratings and Recommendations by outbrain