Short question: In Freeform notification templates... where does it get its field data from? What's the best way to manipulate field data before the notification template gets a hold of it? Is there a custom FieldType method to use to process that data for the notification template?
Long question: There may be a better way to go about this but I'm attempting to build a custom FieldType for Freeform to accommodate inputs with multi-dimensional arrays. The user would be able to click an 'add employer' button to keep adding more employers to their work history. The reason why I'm going this route is to prevent having to create a hundred fields with names 'employer_business_1', 'employer_zip_1', 'employer_business_2', etc.
I've got a custom FieldType working great when placing the field data into the database, but I can't seem to get the data into a notification template. Where is the notification template getting its data from? My pipe separated data never makes it into my notification template.
I've embedded a template into my notification template so I can use PHP to manipulate the field data but it simply comes in as 'ArrayArray'.
An example of the form inputs:
<div class="employer_wrapper">
<label for="business">Place of Employment:</label>
<input type="text" id="business" name="employer_array[0][business]" value="" />
<label for="occupation">Employment Title or Position:</label>
<input type="text" id="occupation" name="employer_array[0][occupation]" value="" />
<label for="supervisor">Name and Title of Supervisor:</label>
<input type="text" id="supervisor" name="employer_array[0][supervisor]" value="" />
<label for="work_phone">Telephone:</label>
<input type="text" id="work_phone" name="employer_array[0][work_phone]" value="" />
<label for="employed_from">Employed From:</label>
<input type="date" id="employed_from" name="employer_array[0][employed_from]" value="" />
<label for="employed_to">Employed To:</label>
<input type="date" id="employed_to" name="employer_array[0][employed_to]" value="" />
<label for="starting_salary">Starting Salary:</label>
<input type="text" id="starting_salary" name="employer_array[0][starting_salary]" value="" />
<label for="ending_salary">Ending Salary:</label>
<input type="text" id="ending_salary" name="employer_array[0][ending_salary]" value="" />
<label for="address">Business Address:</label>
<input type="text" id="address" name="employer_array[0][address]" value="" />
<label for="city">City:</label>
<input type="text" id="city" name="employer_array[0][city]" value="" />
<label for="state">State:</label>
<input type="text" id="state" name="employer_array[0][state]" value="" />
<label for="zip">ZIP:</label>
<input type="text" id="zip" name="employer_array[0][zip]" value="" />
<label for="reason_for_leaving">Reason for Leaving:</label>
<textarea type="text" rows="5" name="reason_for_leaving" name="employer_array[0][reason_for_leaving]"></textarea>
<label for="business">Place of Employment:</label>
<input type="text" id="business" name="employer_array[1][business]" value="" />
<label for="occupation">Employment Title or Position:</label>
<input type="text" id="occupation" name="employer_array[1][occupation]" value="" />
<label for="supervisor">Name and Title of Supervisor:</label>
<input type="text" id="supervisor" name="employer_array[1][supervisor]" value="" />
<label for="work_phone">Telephone:</label>
<input type="text" id="work_phone" name="employer_array[1][work_phone]" value="" />
<label for="employed_from">Employed From:</label>
<input type="date" id="employed_from" name="employer_array[1][employed_from]" value="" />
<label for="employed_to">Employed To:</label>
<input type="date" id="employed_to" name="employer_array[1][employed_to]" value="" />
<label for="starting_salary">Starting Salary:</label>
<input type="text" id="starting_salary" name="employer_array[1][starting_salary]" value="" />
<label for="ending_salary">Ending Salary:</label>
<input type="text" id="ending_salary" name="employer_array[1][ending_salary]" value="" />
<label for="address">Business Address:</label>
<input type="text" id="address" name="employer_array[1][address]" value="" />
<label for="city">City:</label>
<input type="text" id="city" name="employer_array[1][city]" value="" />
<label for="state">State:</label>
<input type="text" id="state" name="employer_array[1][state]" value="" />
<label for="zip">ZIP:</label>
<input type="text" id="zip" name="employer_array[1][zip]" value="" />
<label for="reason_for_leaving">Reason for Leaving:</label>
<textarea type="text" rows="5" name="reason_for_leaving" name="employer_array[1][reason_for_leaving]"></textarea>
I'm using the save() method in my FieldType to turn the data into "|" separated text and store in the database:
public function save($data)
{
if (is_array($data))
{
$data_string = "";
for ($i=0; $i < count($data); $i++)
{
foreach ($data[$i] as $key => $val)
{
$data_string .= $key . "_" . $i . ": " . $val . "|";
}
}
}
$data = $data_string;
return $data;
}
Since the notification template doesn't seem to pull that field data from the database table, what's the best way to manipulate that data before the notification template gets a hold of it? I don't understand where the notifications are pulling the data from and which function to use to process that data.
This is very similar to this post from 2 years ago except I'm attempting to utilize multi-dimensional arrays instead of a single array.