Hi all,
I am at a loss on how to get eForm2db to integrate with Dimmy’s function that dynamically reports just the form fileds that a user has filled out. I want the form fields to get emailed to me in a dynamic report, in a $key.": ".$fields[$key] pair, where only the fields that are filled out are emailed. and I want the $fields2 to get placed in the database. I can’t get them to work together. Here is my best effort, though I don’t understand enough PHP. How do I get this to work?
Any Help would be greatly appreciated.
<?php
$fields2= $fields;//so that the eForm2db could insert the fields2 variables into the db while the nested populate function below would put $fileds in the report chunk.
function escape($s){return mysql_escape_string($s); ///to clean code for db insertion
}
function populatereport ($fields)
{
function eForm2db(&$fields2)
{
global $modx;
// Init our array, name all fields for db insertion
$dbTable = array();
$dbTable['Name'] = $modx->db->escape($fields2['name']);
$dbTable['Email'] = $modx->db->escape($fields2['email']);
$dbTable['Regarding'] = $modx->db->escape($fields2['subject']);
$dbTable['Message'] = $modx->db->escape($fields2['message']);
$dbTable['homePhone'] = $modx->db->escape($fields2['homePhone']);
$dbTable['cellPhone'] = $modx->db->escape($fields2['cellPhone']);
$dbTable['startMonth'] = $modx->db->escape($fields2['startMonth']);
$dbTable['startDay'] = $modx->db->escape($fields2['startDay']);
$dbTable['startTime'] = $modx->db->escape($fields2['startTime']);
$dbTable['endMonth'] = $modx->db->escape($fields2['endMonth']);
$dbTable['endDay'] = $modx->db->escape($fields2['endDay']);
$dbTable['endTime'] = $modx->db->escape($fields2['endTime']);
$dbTable['carSeats'] = $modx->db->escape($fields2['carSeats']);
// Run the db insert query
$dbQuery = $modx->db->insert($dbTable, 'l3ch4t_contactus' );
return true;
}
// Return empty string
return '';
function populate (&$fields) //Dimmy's dynamic report function
{
foreach ($fields as $key => $value)
{
if($fields[$key]){$fields[$key]= $key.": ".$fields[$key];}
}
return true;
}
}
?>
I am clearly just learning PHP. I changed the code to this :
<?php
//so that the eForm2db could insert the fields2 variables into the db while the nested populate function below
function escape($s){return mysql_escape_string($s);
}
function eForm2db(&$fields)
{
$fields2 = $fields;
foreach ($fields as $key => $value)
{
if($fields[$key]){$fields[$key]= $key.": ".$fields[$key];}
}
global $modx;
// Init our array
$dbTable = array();
$dbTable['Name'] = $modx->db->escape($fields2['name']);
$dbTable['Email'] = $modx->db->escape($fields2['email']);
$dbTable['vehicle'] = $modx->db->escape($fields2['subject']);
$dbTable['Message'] = $modx->db->escape($fields2['message']);
$dbTable['homePhone'] = $modx->db->escape($fields2['homePhone']);
$dbTable['cellPhone'] = $modx->db->escape($fields2['cellPhone']);
$dbTable[startDate] = date( 'F j, g a', strtotime( $fields['startDate'] ) );
$dbTable['startMonth'] = $modx->db->escape($fields2['startMonth']);
$dbTable['startDay'] = $modx->db->escape($fields2['startDay']);
$dbTable['startTime'] = $modx->db->escape($fields2['startTime']);
$dbTable['endMonth'] = $modx->db->escape($fields2['endMonth']);
$dbTable['endDay'] = $modx->db->escape($fields2['endDay']);
$dbTable['endTime'] = $modx->db->escape($fields2['endTime']);
$dbTable['carSeats'] = $modx->db->escape($fields2['carSeats']);
$dbtable['createDate'] = strtotime("now");
// Run the db insert query
$dbQuery = $modx->db->insert($dbTable, 'l3ch4t_contactus' );
return '';
}
?>
and it now posts entered data into database and sends out dimmy’s dynamic report. I need to fix a bit with validation and time stamping as well. I hope this helps another newbie.