How to add blocks of description or instructions to a FormTools form by using Hooks Manager to prefill a “Comment/Instruction” field
First create a field in your form to hold this description or comment, and make sure to set the field type and size so that it will hold and display the description text.
I use Field Type “Text Area” when I need a large block of description; otherwise I use a text box. For Text Area, I might use these settings:
Field Size Large Text
Date Type String
DB Column Whatever name you want as the actual database field name
In order to prevent the displaying of the actual Field Name (In my case I only am interested in showing the pre-filled content of the field to the form user, not the Form Field Display name), I change the Field settings to have a Display Text setting of <font color="white">Descrip1|</font> (replacing Descrip1 with your Display Text for this field), which in my form’s case makes the Display Text invisible to the form user against the background color, and causes the Comment/Instructions to appear to be a standalone text block.
Create as many fields as you need to hold the comment/instructions on your form.
Edit your View and make sure the comment/instruction fields are placed where you want them to appear, and uncheck “Editable”
After installing the Hooks Manager, open the module and create a new Rule, name it something such as “Prefill YourFormName with User Instructions”
I use a priority of 51
Hook Type Code Hook
Select Hook Type of ft_create_blank_submission, end
Sample PHP Code – In the sample code below, replace the field name “Descrip1” with the actual field name you are using to display this Instruction/Comment. Set the value of $descrip = whatever text you want to appear on the form, and replace the form number in $form_id == 4 with whatever your actual form number is. Inside the If statement, you can repeat the block for $descrip= and the block for mysql_query(… for each field you are prefilling. Or, you can write a more elegant bit of PHP to prefill more than one field with this same Hook.
Here is the sample PHP Code:
Global $g_table_prefix;
//This code creates longer field descriptions and comments by adding field default information to certain fields that are used as descriptions for other fields, for the Form ######.
If ($form_id == 4){ //only do code if this is Form #_
$descrip = ‘Whatever information you want to tell your form user goes here. It can be quite long, depending on what you have specified in your Field Settings back in the Form Itself. ';
mysql_query("UPDATE {$g_table_prefix}form_{$form_id} SET Descrip1 = '$descrip' WHERE submission_id = $new_submission_id");
}
First create a field in your form to hold this description or comment, and make sure to set the field type and size so that it will hold and display the description text.
I use Field Type “Text Area” when I need a large block of description; otherwise I use a text box. For Text Area, I might use these settings:
Field Size Large Text
Date Type String
DB Column Whatever name you want as the actual database field name
In order to prevent the displaying of the actual Field Name (In my case I only am interested in showing the pre-filled content of the field to the form user, not the Form Field Display name), I change the Field settings to have a Display Text setting of <font color="white">Descrip1|</font> (replacing Descrip1 with your Display Text for this field), which in my form’s case makes the Display Text invisible to the form user against the background color, and causes the Comment/Instructions to appear to be a standalone text block.
Create as many fields as you need to hold the comment/instructions on your form.
Edit your View and make sure the comment/instruction fields are placed where you want them to appear, and uncheck “Editable”
After installing the Hooks Manager, open the module and create a new Rule, name it something such as “Prefill YourFormName with User Instructions”
I use a priority of 51
Hook Type Code Hook
Select Hook Type of ft_create_blank_submission, end
Sample PHP Code – In the sample code below, replace the field name “Descrip1” with the actual field name you are using to display this Instruction/Comment. Set the value of $descrip = whatever text you want to appear on the form, and replace the form number in $form_id == 4 with whatever your actual form number is. Inside the If statement, you can repeat the block for $descrip= and the block for mysql_query(… for each field you are prefilling. Or, you can write a more elegant bit of PHP to prefill more than one field with this same Hook.
Here is the sample PHP Code:
Global $g_table_prefix;
//This code creates longer field descriptions and comments by adding field default information to certain fields that are used as descriptions for other fields, for the Form ######.
If ($form_id == 4){ //only do code if this is Form #_
$descrip = ‘Whatever information you want to tell your form user goes here. It can be quite long, depending on what you have specified in your Field Settings back in the Form Itself. ';
mysql_query("UPDATE {$g_table_prefix}form_{$form_id} SET Descrip1 = '$descrip' WHERE submission_id = $new_submission_id");
}