Email coding task on form submission

Status
Not open for further replies.

stevelis

Member
The email needs to confirm only the selected options made on the form via the form's Email Plugin.
I would appreciate some coding assistance for the Message Text, so that the email will only include the 'Yes' selections made from the "Yes/No field" Element Plugins. (see desired email layout below)
Basically the coding needs to filter the 'Yes' selections and then print the 'Label' value of that Element as part of the email's content. I have achieve the other text content and layout 0f the email.
There are 15 "Yes/No field" Elements in one group and another 13 "Yes/No field" Elements in the second group all with 'No' as the default value.
Db tbl is name - eoi
List Name is - Expressions
Form Label is - Expressions
The 2 Groups Names are eoi_chreg and eoi_tmreg

The email would look something like the following with each selection listed underneath each other.
Also, some people may not make a selection from one of the groups. If that was the case then the example below would still display the text in bold, but no label values.

You have registered the following Chair expressions -
'label Name" of element from the eoi_chreg group
'label Name" of element from the eoi_chreg group
'label Name" of element from the eoi_chreg group
You have registered the following Team Member expressions -
'label Name" of element from the eoi_tmreg group
'label Name" of element from the eoi_tmreg group
'label Name" of element from the eoi_tmreg group

Hope I have explained my coding needs without confusing people

Thanks
Steve
Australia
 
You need a php template (located in ...plugins\fabrik_form\email\tmpl\debug.php) with code something like
Code:
<?php
 
// No direct access
defined('_JEXEC') or die('Restricted access');
//do a var_dump to see your elements/element_raws
echo '<pre>';
var_dump($this->data);
 
//yesno_raw is an array
if ($this->data['eoi___yesno_raw'][0] == '1')
{
echo $this->data['eoi___elementx'];
}
?>

See also debug.php and debug_with_labels.php for examples.
 
Hi troester
I have attempted these steps resulting in the following snapshot of the email sent received below
Step 1 - make a copy of the existing debug.php and rename to debugeoi.php in the same folder.
Step 2 - deleted the existing coding at line 14, adding the above coding starting at line 14
Step 3 - then went to Forms, Email Plugin, Options, PHP /HTML Template and selected the newly created debugeoi.php .
Any pointers where I should be looking?
Is my understanding way off, or is it in the coding
["eoi___vsc_raw"]=>
array(1) {
[0]=>
string(1) "1"
}
["eoi___dvs_raw"]=>
array(1) {
[0]=>
string(1) "1"
}
["eoi___cnr_raw"]=>
array(1) {
[0]=>
string(1) "1"
}
["eoi___v8u_raw"]=>
array(1) {
[0]=>
string(1) "0"
}
["eoi___f4c_raw"]=>
array(1) {
[0]=>
string(1) "0"
Notice:Undefined index: eoi___yesno_raw in ........../plugins/fabrik_form/email/tmpl/debugeoi.php on line 25

Thanks
Steve
Australia
 
The var_dump is only to show your element names and structure in $this->data
Did you shorten the output?
Is e.g. vsc a yesno element?
If so your code could be
Code:
<?php
 
// No direct access
defined('_JEXEC') or die('Restricted access');
//do a var_dump to see your elements/element_raws
//echo '<pre>';
//var_dump($this->data);
 
//vsc_raw is an array
if ($this->data['eoi___vsc_raw'][0] == '1')
{
echo $this->data['eoi___one-of-your-elements'];
}
?>
 
Hi troester
All the elements in the eoi_chreg group and eoi_tmreg group are the yesno Elements.
The first group, eoi_detreg are mainly field elements for names, location and contact details etc
Now trying your second code

Thanks
Steve
Australia
 
Hi troester
Tried the 2nd coding with this error in the email
Notice: Undefined index: eoi___one-of-your-elements in /home/camsjac/public_html/plugins/fabrik_form/email/tmpl/eoi.php on line 30
which is this line
echo $this->data['eoi___one-of-your-elements'];


Steve Australia
 
Sure, you must replace one-of-your-elements with one of your element names you want to display.

 
Hi troester
I missed that one, nearly midnight in Australia
I have a multiple number of yesno elements in two groups
Is there any coding that would address this issue of multiple yesno elements in each "Group"

Steve
Australia
 
The debug_with_labels.php in the email plugin is the format I looking for but I don't need all the element fields.
How and where can the existing code be edited to display;
A. two selected elements, eoi___name, (calculation) and eoi___grade (field)
B. only the Yesno elements with the Yes option selected. There are 25 of these elements with No as the default value on all
(eoi___vsc, eoi___dvs, eoi___v8u are 3 of the 25 Yesno elements

Steve
Australia

// No direct access
defined('_JEXEC') or die('Restricted access');
// Alter these settings to limit what is shown in the email:
// Set this to show the raw element values.
$raw = false;
// Set this to true to show non element field values in the email e.g. "option: com_fabrik"
$info = false;

/**
* Will attempt to get the element for the posted key
*
* param object $formModel Form model
* param string $key POST key value
*
* @return array(label, is the key a raw element, should we show the element)
*/
function tryForLabel($formModel, $key, $raw, $info)
{
$elementModel = $formModel->getElement($key);
$label = $key;
$thisRaw = false;
if ($elementModel)
{
$label = $elementModel->getElement()->label;
}
else
{
if (substr($key, -4) == '_raw')
{
$thisRaw = true;
$key = substr($key, 0, strlen($key) - 4);
$elementModel = $formModel->getElement($key);
if ($elementModel)
{
$label = $elementModel->getElement()->label . ' (raw)';
}
}
}
$show = true;
if (($thisRaw && !$raw) || (!$elementModel && !$info))
{
$show = false;
}
return array($label, $thisRaw, $show);
}
?>
<table>
<?php
foreach ($this->emailData as $key => $val)
{
// Lets see if we can get the element name:
list($label, $thisRaw, $show) = tryForLabel($formModel, $key, $raw, $info);
if (!$show)
{
continue;
}
echo '<tr><td>' . $label . '</td><td>';
if (is_array($val)) :
foreach ($val as $v):
if (is_array($v)) :
echo implode("<br>", $v);
else:
echo implode("<br>", $val);
endif;
endforeach;
else:
echo $val;
endif;
echo "</td></tr>";
}

?>
</table>
 
Code:
if ($this->data['eoi___vsc_raw'][0] == '1')
{
echo $this->data['eoi___one-of-your-elements'];
}
This is how you get the data of your single elements.
 
thanks troester for the quick reply, as my understanding of writing php is limited - perhaps too limited.
if I understand correctly, I would repeat the two lines of code for all the required element and replacing ['eoi___one-of- your-elements'] with ['eoi___vsc'] and ['eoi___vsc'] etc


Steve
Australia
 
The following code is providing the required information but need a couple of modifications
A. echo $this->data['eoi___v8u']; is returning the Yes value of the element where as I need to display the element's label value, i.e. V8 Ute
B. the information is all displayed in a row. How do I achieve a single row for each value

Thanks again

Steve
Australia


// No direct access
defined('_JEXEC') or die('Restricted access');
//do a var_dump to see your elements/element_raws
//echo '<pre>';
//var_dump($this->data);

//vsc_raw is an array
if ($this->data['eoi___name'])
{
echo $this->data['eoi___name'];
}
if ($this->data['eoi___v8u_raw'][0] == '1')
{
echo $this->data['eoi___v8u'];
}
if ($this->data['eoi___dvs_raw'][0] == '1')
{
echo $this->data['eoi___dvs'];
}
if ($this->data['eoi___cnr_raw'][0] == '1')
{
echo $this->data['eoi___cnr'];
}
if ($this->data['eoi___v8u_raw'][0] == '1')
{
echo $this->data['eoi___v8u'];
}

?>
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top