Contactformgenerator to database enhancement

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Contactformgenerator to database enhancement

Post by marcus@localhorst »

Hi,
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']);
--[ADD-AFTER]--

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*/
search from line 900

Code: Select all

unset($mail);
//}
$form_cnt = '';
--[ADD-AFTER]--

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().'');
    }

 }
Save the file.

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 :D

TODO:
- switch store only, both store and mailmail, mail only
- more secure

greetings marcus
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

i like "quick and dirty"

Post by phalancs »

Hey marcus, this is wonderful! I will definitely have a look! If it works, then it is a perfect addition!

Thumbs up!
2008
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Nice one
been waiting for this for a long time...

TriP
typoid
Posts: 16
Joined: Wed 25. Jan 2006, 18:12

see data

Post by typoid »

is there any easy way to make this data stored in the db visible in backend?
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

at the moment i use webxadmin (http://webxadmin.free.fr/article/webxadmin-v2-185.php) for editing the tables and show data.
it's very fast to setup via XML.
I#ve had teh idea to integrate webxadmin in phpwcms as module.
but no time at the moment...

greetings
marcus
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

hey marcus, great tool, will check that! Would be great to have that in admin, but i don't hope that we are all working on improving things and the 1.3 veriosn of phpwcms will make all our efforts obsolete.

Thanx so far :)
2008
selbaer
Posts: 93
Joined: Sun 22. Jan 2006, 02:19
Location: Florida West Coast

Post by selbaer »

phalancs wrote:hey marcus, great tool, will check that! Would be great to have that in admin, but i don't hope that we are all working on improving things and the 1.3 veriosn of phpwcms will make all our efforts obsolete.

Thanx so far :)
and?
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

selbaer wrote:
phalancs wrote:hey marcus, great tool, will check that! Would be great to have that in admin, but i don't hope that we are all working on improving things and the 1.3 veriosn of phpwcms will make all our efforts obsolete.

Thanx so far :)
and?
Notice that...
phalancs wrote:and the 1.3 version of phpwcms will make all our efforts obsolete.
Looks like it SURE did become too hard to anticiapte OliverG's changes! ;-)
Post Reply