this describe a quick and dirty hack to use the contactformgenerator for storing data into a userdefined databasetable. if you have some better php skills than me, it would be cool if you look at the code and tell us improvements.
I made this hack, because I need it and there was a very good basic to start with . Let's go:
Target: using the contactformgenerator to send Mail and store this data into an own MySQL Table.
Level: need some PHP/MySQL basics to enhance the code
Status: experimental
open include/inc_front/cnt23.article.inc.php
search from Line 780
Code: Select all
$cnt_form['template'] = preg_replace('/\{'.$POST_key.'\}/i', $POST_keyval, $cnt_form['template']);
Code: Select all
//echo $POST_key." : ".$POST_keyval."<br />";
/* MODIFY to store Data*/
if (!(strpos($POST_key,"h_")===false)){
// fields that we named h_fieldname will not written in the DB so we skip it.
// But this h_fieldnames tell us (or the script) that we want to write in a database
// see below
$nosql = 1;
}else{
//build list of fieldnames and fieldcontent - I don't found a function arraytolist in php :-(
$tbllist .= $POST_key.",";
$vallist .= "'".mysql_real_escape_string($POST_keyval)."',";
/* MODIFY to store Data*/
Code: Select all
unset($mail);
//}
$form_cnt = '';
Code: Select all
/* MODIFY to store Data*/
// this print the mailcontent into the success page.
$form_cnt = "<div>";
$form_cnt = nl2br($cnt_form['template']);
$form_cnt .= "</div>";
//print_r($POST_val);
// remove the las comma from each list
$tbllist = substr($tbllist, 0 , strlen($tbllist)-1);
$vallist = substr($vallist, 0 , strlen($vallist)-1);
$sql= "INSERT INTO ".$_POST['h_dbt']." (".$tbllist.") VALUES (".$vallist.")";
// $_POST['h_dbt'] h_dbt ist the fieldname which hold the DB tablename
// maybe this is very unsecure, how to solve that? MD5 hash?
if ($nosql) {
$result = mysql_query($sql,$db);
if (!$result) {
die('Ungültige Abfrage: ' . mysql_error().'');
}
}
then setup a contactform and add the hidden field h_dbt this holds the tablename (as default value) where you want to write in.
ATTENTION! i think this is very unsecure if you have a better solution, please post it!
that's all
So, to write in a dbtable + send the mailform as mail you need to add a hiddenfield h_dbt with the tablename. then you can setup fields named with h_xxx as hiddenfield or anything else, to send informations only in mailcontent and don't store in the db.
hope you understand this. but if you understand the code, you will know how to use it
And, if you improve the code, please post it
TODO:
- switch store only, both store and mailmail, mail only
- more secure
greetings marcus