<?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_query] = $fields[query]; //query
// INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’modx_form_results’ );
// UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix . ’modx_form_results’ );
// DELETE - $dbQuery = $modx->db->delete( $table_prefix . ’deleteFromTableName’, ’some_field = 1 AND name=\’’.$dbTable[modx_form_results].’\’’, ’’ );
// etc...
// Run the db insert query
$dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’modx_form_results’ );
return true;
}
// Return empty string
return ’’;
?>
<?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;
$sql = ("select * from `competitionEntries` where `email` = '".$fields['email']."'");
$result = $modx->db->query($sql);
return $result;
$num = mysql_num_rows($result);
if( $num > 0 )
{
// Set placeholders
$chunkArr = array('dupe_entry' => 'It appears you have already entered the contest. Only one entry per person is allowed. If you have a question or feel there is a problem please <a href="index.php?id=5">click here to contact us</a>. Thank you.');
//Output the dupe alert
//echo $modx->parseChunk( 'dupe_entry_tpl', $chunkArr, '[+', '+]' );
echo 'It appears you have already entered the contest. Only one entry per person is allowed';
// Prevent form load
return true;
}else
{
// Init our array
$dbTable = array(); // key = DB Column; Value = Insert/Update value
// Insert field/value pairs to insert/update in our table
$dbTable[firstName] = $fields[firstName];
$dbTable[lastName] = $fields[lastName];
$dbTable[address] = $fields[address];
$dbTable[suburb] = $fields[suburb];
$dbTable[state] = $fields[state];
$dbTable[postcode] = $fields[postcode];
$dbTable[email] = $fields[email];
$dbTable[daytimePhone] = $fields[daytimePhone];
$dbTable[mobilePhone] = $fields[mobilePhone];
$dbTable[heardAbout] = $fields[heardAbout];
$dbTable[termsConditions] = $fields[termsConditions];
$dbTable[subscribe] = $fields[subscribe];
$dbTable[entryDate] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Message the postdate timestamp to be MySQL insert friendly
// INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'competitionEntries' );
// UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix . 'competitionEntries' );
// DELETE - $dbQuery = $modx->db->delete( $table_prefix . 'competitionEntries', 'some_field = 1 AND name=\''.$dbTable[name].'\'', '' );
// etc...
// Run the db insert query
//$dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'competitionEntries' );
$dbQuery = $modx->db->insert( $dbTable, 'competitionEntries' );
}//end if else
return true;
}
// Return empty string
return '';
?>$dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'modx_form_results' );
<?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;
$num = 0;
//$tmpEmail = $fields[email];
//$sql = ("select * from `competitionEntries` where `email` = '".$fields['email']."'");
$sql = ("select * from `competitionEntries` where `email` = '$tmpEmail'");
/*$sql = ("select * from `competitionEntries`");
while( $row = $modx->fetchRow($sql) ){
$storeEmail = $row->email;
if ($storeEmail== $tmpEmail)
{
$num ++;
}else
{
}
}
*/
$result = $modx->db->query($sql);
$num = $modx->db->getRecordCount($result);
//$result= $result->fetchAll(PDO_FETCH_ASSOC);
//return $result;
//$num = mysql_num_rows($result);
if ($num < 0)
{
// Set placeholders
$chunkArr = array('dupe_entry' => 'It appears you have already entered the contest. Only one entry per person is allowed. If you have a question or feel there is a problem please <a href="index.php?id=5">click here to contact us</a>. Thank you.');
//Output the dupe alert
echo $modx->parseChunk( 'dupe_entry_tpl', $chunkArr, '[+', '+]' );
//echo 'It appears you have already entered the contest. Only one entry per person is allowed';
// Prevent form load
return true;
}else
{
// Init our array
$dbTable = array(); // key = DB Column; Value = Insert/Update value
// Insert field/value pairs to insert/update in our table
$dbTable[firstName] = $fields[firstName];
$dbTable[lastName] = $fields[lastName];
$dbTable[address] = $fields[address];
$dbTable[suburb] = $fields[suburb];
$dbTable[state] = $fields[state];
$dbTable[postcode] = $fields[postcode];
$dbTable[email] = $fields[email];
$dbTable[daytimePhone] = $fields[daytimePhone];
$dbTable[mobilePhone] = $fields[mobilePhone];
$dbTable[heardAbout] = $fields[heardAbout];
$dbTable[termsConditions] = $fields[termsConditions];
$dbTable[subscribe] = $fields[subscribe];
$dbTable[entryDate] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Message the postdate timestamp to be MySQL insert friendly
// INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'competitionEntries' );
// UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix . 'competitionEntries' );
// DELETE - $dbQuery = $modx->db->delete( $table_prefix . 'competitionEntries', 'some_field = 1 AND name=\''.$dbTable[name].'\'', '' );
// etc...
// Run the db insert query
//$dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'competitionEntries' );
$dbQuery = $modx->db->insert( $dbTable, 'competitionEntries' );
}//end if else
return true;
}
// Return empty string
//return '';
?>