I have decided to try one more time to see if I can get it to work. Here is what I have. MY database table is called modx_form_results and is located in the default Modx Database.
Database Fields
Field= con_id, Type=int(10), Null=No, Extra=auto_increment
Field= con_name, Type = varchar Null=Yes
Field= con_email, Type = varchar Null=Yes
Field= con_company, Type = varchar Null=Yes
Field= con_query, Type=longtext Null=Yes
Field= con_date, Type = timestamp Null=No, Default =Current_timestamp
My snippet code is as follows
<?php
function eForm2db ( &$fields )
{
/*---------------------------------------------------------------
eForm2db
Version: 0.1 [Beta 1]
Author: pixelchutes
---------------------------------------------------------------
Requirements:
eForm 1.4+
---------------------------------------------------------------
Use:
- Takes validated eForm submittal data for use with the MODx DBAPI extender class.
- Easily process database records referencing your form submission data:
+ INSERT new records to a table of your choice
+ UPDATE existing records if you'd prefer
+ DELETE records based on form submittal criteria
+ Form a query and return its record set as XML using $modx->db->getXML
+ Query a table's MetaData using $modx->db->getTableMetaData, followed by an update
query on only the form fields that are named after table columns!
+ and much more!
---------------------------------------------------------------*/
// Bring needed resources into scope
global $modx, $table_prefix;
// Init our array
$dbTable = array(); // key = DB Column; Value = Insert/Update value
// Insert field/value pairs to insert/update in our table
$dbTable[con_name] = $fields[name]; // Name Field
$dbTable[con_email] = $fields[email]; //email
$dbTable[con_company] = $fields[company]; //company
$dbTable[con_date] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Massage
the postdate timestamp to be MySQL insert friendly
$dbTable[con_query] = $fields[query]; //query
// INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix .
'insertTableName' );
// UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix .
'updateTableName' );
// DELETE - $dbQuery = $modx->db->delete( $table_prefix . 'deleteFromTableName',
'some_field = 1 AND name=\''.$dbTable[form_results].'\'', '' );
// etc...
// Run the db insert query
$dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'form_results' );
return true;
}
// Return empty string
return '';
?>
The call from the page is as follows:
Call from the page:
[[eForm2db]]
[!eForm? &formid=`ContactForm` &to=`[email protected]` eFormOnBeforeMailSent=`eForm2db` &tpl=`ContactForm` report=`ContactFormReport` &thankyou=`ContactFormThanks` &subject=`Web site feedback` &cssStyle=`assets/templates/mystyle.css` !]
I am not an expert at MODx as you can guess and I must be doing something totally stupid as everybody else seems to get this working very easilly.
Thanks again for your help. Let me know if you see something obvious. I have been looking at this for too long.