Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
plugin save zem_contact to DB
Hi
I coded a little plugin that work with zem_contat_reborn 4.0.3.20 that save the data to a DB table before sending the email, but sometimes the operation fails and i dont know what cause that, the email is sent correctly but the data is not stored!
Here is the code of the plugin:
/**
Registers the callback. dzd_mailverif_function() is
now loaded on 'zemcontact.submit' event. You can find
the callback spot from ZRC's source and what it can offer.
*/
register_callback('dzd_mailtodb','zemcontact.submit');
/**
The function that does the work on
the submit event
*/
function dzd_mailtodb() {
$evaluation =& get_zemcontact_evaluator();
/*
It's spam, end here
*/
if($evaluation->get_zemcontact_status() != 0)
return;
/*
Saving the data goes here etc..
$zem_contact_values global etc. can be
used to get the data and so on.
*/
global $zem_contact_values;
$set = 'timestamp=NOW()';
$uid = md5(uniqid(rand(),true));
$if_ins = $zem_contact_values['dzd_mailtodb'] ? 1 : 0;
if ($if_ins)
{
$expvar = var_export($zem_contact_values, true);
$myid = safe_insert(
"adhere",
"raison = '$zem_contact_values[raison]',
adresse = '$zem_contact_values[adresse]',
ville = '$zem_contact_values[ville]',
wilaya = '$zem_contact_values[wilaya]',
telephone = '$zem_contact_values[telephone]',
mobile = '$zem_contact_values[mobile]',
fax = '$zem_contact_values[fax]',
Email = '$zem_contact_values[Email]',
nature = '$zem_contact_values[nature]',
secteur = '$zem_contact_values[secteur]',
branche = '$zem_contact_values[branche]',
rc = '$zem_contact_values[rc]',
nif = '$zem_contact_values[nif]',
ai = '$zem_contact_values[ai]',
nis = '$zem_contact_values[nis]',
nom = '$zem_contact_values[nom]',
representant = '$zem_contact_values[representant]',
conseil = '$zem_contact_values[conseil]',
candidat = '$zem_contact_values[candidat]',
candidatregion = '$zem_contact_values[candidatregion]'"
);
if ($myid<>''){
$zem_contact_values['insertion'] = 'Votre formulaire est enregistré';
} else {
$zem_contact_values['insertion'] = 'En Attente : Erreur insertion DB'.$expvar;
}
}
}
I suspected that maybe the information sent caused some sql error, but when i insert the data using the sql statement it works!
Can someone see if i am missing something?
Thanks and happy new year txp!
Offline
Re: plugin save zem_contact to DB
Hi Dragondz and happy 20166
There is a similar plugin by etc which might be of help.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: plugin save zem_contact to DB
Thank, Yianis
I looked at the code and it seems similar to mine, but i still dont know why it works most of time and why sometime it fails!
Offline
Re: plugin save zem_contact to DB
You’re not using doSlash()
on the data you insert into the database. That could cause SQL error, but does also introduce an SQL injection vulnerability. You can fix it like this:
$values = doSlash($zem_contact_values)
$expvar = var_export($values, true);
$myid = safe_insert(
"adhere",
"raison = '$values[raison]',
adresse = '$values[adresse]',
...
Offline
Re: plugin save zem_contact to DB
Thanks Ruud
The code has been updated.
Offline
#6 2016-01-05 21:58:55
- gomedia
- Plugin Author
- Registered: 2008-06-01
- Posts: 1,373
Re: plugin save zem_contact to DB
Hi Dragondz,
I’ve had a beta version of adi_contact sitting around for a while that does the same sort of thing.
You’re welcome to have a look … there’s a pretty good chance that doSlash() will sort things out for you.
Offline
Re: plugin save zem_contact to DB
Hi Thanks for the plugin.
I will take look at it, i am waiting a day or two to see if things goes well.
Offline
Pages: 1