2015-02-21, 23:29:09
Hi Cumbe and everyone
Re .. Bugs fixed, Here is an edited version of v5823
I am using this contact form plugin from Cumbe, but on downloading the latest version v5823, I had some bugs. I have fixed all the bugs that I have seen, and the contact form is now working well. Also, I added a little extra functionality to v5823, but this does NOT affect the original functionality.
So the reason for this post is that I offer you my bug fixed version and also the added functionality. … but I am not the original author, just trying to help. The edited files are included below.
First a important note : I have only ever used the PHPmailer class. In the contact form there are 2 send methods, which you can choose with function param ‘sendphpmail’ : false : use php mail() fn, true : use the PHPMailer class. In testing my bug fixes and functionality changes, I have only ever used/tested the PHPMailer class, and never the php mail() fn ... So if there any problems on he php mail() side them I have not look at these. But I have not touched the code for the actual send process using the other php mail() function … so I hope I have not broken that side … apologies if I have !
Indyana : I have not included your possible mod to possible problem, in you last post re canonical redirects.
... So all mods are relative to version 5823 :
1. Bugs fixed - general
a. Captcha validation enable / disable : If function param ‘captcha’ is set false, then now NO captcha validation is done AND the captcha fields are not shown in the contact form
b. Moved the add_action('pages-sidebar', …) fn in cbcontact_form.php to inside the if (basename($_SERVER, …)) {.. } block. .. otherwise had language switching problems (I have a multilanguage site) … a Cumbe mod, but not in v5823
2. Bugs fixed – PHPMailer
a. Put PHPMailer send() and some add email address fns in a try/catch, to catch otherwise uncaught exceptions when have send problems.
b. v5823 : $message->FromName = $from = > Changed to : Mail->fromEmail = $from .. otherwsie have problems
3. Functional changes – General
a. Add the following 2 boolean configs .. in my edited cbcontact_form.php, line 322 and 329 .. to change their true/false values change them directly in the code. (I did not want to change the cbcontact_page() fn param list) :
b. $display_jsalert_boolean
i. true => Display success/error message on send in a javascript alert box (as v5823)
ii. false => Display success/error message on send in the html at the top of the re-output contact form , colour blue = success, red = error
c. $required_fields_all_boolean
i. true => All four contact form textfields are required
ii. false => Only the fields 'Name' and 'Subject' are required (as v5823)
d. input param $usu - the GS admin username, used to look up his email address in the GS admin => This can now also be directly an email address and will be accepted as such, exactly in the same way as the ‘other users’ $usus
e. Tidy code : Since I was doing a number of changes, I generally tidied some code here and there, to make it clearer to understand, at least for me, but functionality not changed because of this.
4. General PHPMailer setup
a. In my edited comprueba.php file I have all the PHPMailer params setup for my needs as follows
b. Note the API description for PHPMiler is at : http://phpmailer.github.io/PHPMailer/cla...ailer.html
c. In general, for your particular setup you need to assign some or all of the following
i. $mail->IsSMTP() / isMail() / isSendmail()
ii. $mail->SMTPSecure = "" / "ssl" / "tls"
iii. $mail->Host = "my.server.name"; // specify SMTP Server name
iv. $mail->Port = 25; // specify SMTP Server port nr, default = 25
v. $mail->SMTPAuth = true/false ; // turn on/off SMTP authentication
vi. $mail->Username = "me@myusername.com"; // SMTP username
vii. $mail->Password = "mypassword"; // SMTP password
d. As an example, for my needs I have => I am sending over SMTP to my website hoster’s smtp mail server, which has the same server name as my hoster, so smtp server is localhost, and authentication is required :
i. $mail->IsSMTP(); // send mail over SMTP
ii. // $mail->SMTPSecure = xx // no ssl/tls required (at the moment), default = “” = not secure
iii. $mail->Host = "localhost"; // smtp server is same as my hoster
iv. $mail->Port = 25; // This is the default anyway
v. $mail->SMTPAuth = true; // Require SMTP username / password to send
vi. $mail->Username = "me@myusername.com"; // SMTP username (dummy)
vii. $mail->Password = "mypassword"; // SMTP password (dummy)
.
5. So here are the files … use them all together, just replace the original with these. Not, the css file is not necessary, but I just changed it a bit so looked better for me. PS to everyone .. is there a better place in the future to upload whole files ? , as I think code tags are really only meant for code snippets.
6. Tell me if it has improved things for you
7. Cumbe, if you have time can you check through these mods and see what you think, and maybe you can include the mods in an updated version of the proper online version, that would be great
Regards Aldebaran
cbcontact_form.php :
cbcontact/comprueba.php :
cbcontact/form/cbcontact.php :
cbcontact/form/cbcontact.css
(not really necessary, just to improve display ) :
Re .. Bugs fixed, Here is an edited version of v5823
I am using this contact form plugin from Cumbe, but on downloading the latest version v5823, I had some bugs. I have fixed all the bugs that I have seen, and the contact form is now working well. Also, I added a little extra functionality to v5823, but this does NOT affect the original functionality.
So the reason for this post is that I offer you my bug fixed version and also the added functionality. … but I am not the original author, just trying to help. The edited files are included below.
First a important note : I have only ever used the PHPmailer class. In the contact form there are 2 send methods, which you can choose with function param ‘sendphpmail’ : false : use php mail() fn, true : use the PHPMailer class. In testing my bug fixes and functionality changes, I have only ever used/tested the PHPMailer class, and never the php mail() fn ... So if there any problems on he php mail() side them I have not look at these. But I have not touched the code for the actual send process using the other php mail() function … so I hope I have not broken that side … apologies if I have !
Indyana : I have not included your possible mod to possible problem, in you last post re canonical redirects.
... So all mods are relative to version 5823 :
1. Bugs fixed - general
a. Captcha validation enable / disable : If function param ‘captcha’ is set false, then now NO captcha validation is done AND the captcha fields are not shown in the contact form
b. Moved the add_action('pages-sidebar', …) fn in cbcontact_form.php to inside the if (basename($_SERVER, …)) {.. } block. .. otherwise had language switching problems (I have a multilanguage site) … a Cumbe mod, but not in v5823
2. Bugs fixed – PHPMailer
a. Put PHPMailer send() and some add email address fns in a try/catch, to catch otherwise uncaught exceptions when have send problems.
b. v5823 : $message->FromName = $from = > Changed to : Mail->fromEmail = $from .. otherwsie have problems
3. Functional changes – General
a. Add the following 2 boolean configs .. in my edited cbcontact_form.php, line 322 and 329 .. to change their true/false values change them directly in the code. (I did not want to change the cbcontact_page() fn param list) :
b. $display_jsalert_boolean
i. true => Display success/error message on send in a javascript alert box (as v5823)
ii. false => Display success/error message on send in the html at the top of the re-output contact form , colour blue = success, red = error
c. $required_fields_all_boolean
i. true => All four contact form textfields are required
ii. false => Only the fields 'Name' and 'Subject' are required (as v5823)
d. input param $usu - the GS admin username, used to look up his email address in the GS admin => This can now also be directly an email address and will be accepted as such, exactly in the same way as the ‘other users’ $usus
e. Tidy code : Since I was doing a number of changes, I generally tidied some code here and there, to make it clearer to understand, at least for me, but functionality not changed because of this.
4. General PHPMailer setup
a. In my edited comprueba.php file I have all the PHPMailer params setup for my needs as follows
b. Note the API description for PHPMiler is at : http://phpmailer.github.io/PHPMailer/cla...ailer.html
c. In general, for your particular setup you need to assign some or all of the following
i. $mail->IsSMTP() / isMail() / isSendmail()
ii. $mail->SMTPSecure = "" / "ssl" / "tls"
iii. $mail->Host = "my.server.name"; // specify SMTP Server name
iv. $mail->Port = 25; // specify SMTP Server port nr, default = 25
v. $mail->SMTPAuth = true/false ; // turn on/off SMTP authentication
vi. $mail->Username = "me@myusername.com"; // SMTP username
vii. $mail->Password = "mypassword"; // SMTP password
d. As an example, for my needs I have => I am sending over SMTP to my website hoster’s smtp mail server, which has the same server name as my hoster, so smtp server is localhost, and authentication is required :
i. $mail->IsSMTP(); // send mail over SMTP
ii. // $mail->SMTPSecure = xx // no ssl/tls required (at the moment), default = “” = not secure
iii. $mail->Host = "localhost"; // smtp server is same as my hoster
iv. $mail->Port = 25; // This is the default anyway
v. $mail->SMTPAuth = true; // Require SMTP username / password to send
vi. $mail->Username = "me@myusername.com"; // SMTP username (dummy)
vii. $mail->Password = "mypassword"; // SMTP password (dummy)
.
5. So here are the files … use them all together, just replace the original with these. Not, the css file is not necessary, but I just changed it a bit so looked better for me. PS to everyone .. is there a better place in the future to upload whole files ? , as I think code tags are really only meant for code snippets.
6. Tell me if it has improved things for you
7. Cumbe, if you have time can you check through these mods and see what you think, and maybe you can include the mods in an updated version of the proper online version, that would be great
Regards Aldebaran
cbcontact_form.php :
PHP Code:
<?php
/*****************************************************/
/* Aldebaran Edited Version 1.0 */
/* - An edit of Cumbe's plugin 'Contact Form' v5823 */
/*****************************************************/
/*
Name: Simple Cumbe contact form
Description: It is a simple contact form
Version: 5.8.2.3
Author: Cumbe (Miguel Embuena Lance)
Author URI: http://www.cumbe.es/contact/
*/
// Relative
$relative = '../';
$path = $relative. 'data/other/';
# get correct id for plugin
$thisfile=basename(__FILE__, ".php");
# register plugin
register_plugin(
$thisfile,
'Cumbe_contact',
'5.8.2.3',
'Cumbe',
'http://www.cumbe.es/contact/',
'Description: Getsimple contactform.',
'pages', //page type
'vermensajes'
);
//set internationalization
global $LANG;
if (basename($_SERVER['PHP_SELF']) != 'index.php') { // backend only
i18n_merge('cbcontact', $LANG);
i18n_merge('cbcontact', 'en_US');
// New Cumbe Mod
// add to sidebar of admin > pages
add_action('pages-sidebar','createSideMenu',array('cbcontact_form', $i18n['cbcontact/CONTACT']));
}
//add css to head
add_action('theme-header','cbcontact_css');
//check $_SESSION
add_action('index-pretemplate', 'cbcontact_session');
// New Cumbe Mod .. moved to above
// add_action('pages-sidebar','createSideMenu',array('cbcontact_form', $i18n['cbcontact/CONTACT']));
//filter $content
add_filter('content','cbcontact_content');
function cbcontact_css(){
global $SITEURL;
echo '<link href="'.$SITEURL.'plugins/cbcontact/form/cbcontact.css" rel="stylesheet" type="text/css" />';
}
function cbcontact_session(){
if( !isset($_SESSION)){
session_start();
}
}
/* ***************************************************** */
/* Function vermensajes() => list_email_log() */
/* This is called in the backend/admin to display the */
/* contact form pa<ge showing the list of email sent */
/* ***************************************************** */
function vermensajes(){
global $i18n;
$log_name = 'cbcontactform.log';
$log_path = GSDATAOTHERPATH.'logs/';
$log_file = $log_path . $log_name;
?>
<script type="text/javascript">
<!--
function confirmar(formObj,count,msge,bck) {
if(!confirm(msge)) {
return false;
} else {
if (bck == 'log'){
if (count =='n'){
window.location="load.php?id=cbcontact_form&action=delete";
} else {
window.location="load.php?id=cbcontact_form&n_del=" + count + "";
}
}
return false;
}
}
-->
</script>
<?php
if(file_exists($log_file)) {
$log_data = getXML($log_file);
if (@$_GET['action'] == 'delete' && strlen($log_name)>0) {
unlink($log_file);
exec_action('logfile_delete');
?>
<label>Log <?php echo $log_name;?> <?php echo $i18n['MSG_HAS_BEEN_CLR']; ?>
</div>
</div>
<div id="sidebar" >
<?php include('template/sidebar-pages.php'); ?>
</div>
<div class="clear"></div>
</div>
<?php get_template('footer'); ?>
<?php
exit;
}
//delete one register:entry
if (@$_GET['n_del'] != ''){
$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = FALSE;
$domDocument->load($log_file);
$domNodeList = $domDocument->documentElement;
$domNodeList = $domDocument->getElementsByTagname('entry');
$ndel = @$_GET['n_del'];
$ndL = $domNodeList ->item($ndel)->parentNode;
$ndL -> removeChild($domNodeList ->item($ndel));
//sase again modified document
$domDocument->save($log_file);
}
//load data of xml
$log_data = getXML($log_file);
//END delete one register
?>
<label><?php echo $i18n['VIEWING'];?> <?php echo $i18n['LOG_FILE'];?>: ‘<em><?php echo @$log_name; ?></em>’</label>
<div class="edit-nav" >
<?php
echo '<a href="load.php?id=cbcontact_form&action=delete" accesskey="c" title="'.$i18n['CLEAR_ALL_DATA'].' '.$log_name.'" onClick="return confirmar(this,"n","'.$i18n['CLEAR_ALL_DATA'].' '.$log_file.'. '.$i18n['cbcontact/delsure'].'","log")" />'.$i18n['CLEAR_THIS_LOG'].'</a>';
echo '<div class="clear"></div>';
echo '</div>';
echo '<ol class="more" >';
$count = 0;
foreach ($log_data as $log) {
echo '<li><p style="font-size:11px;line-height:15px;" ><b style="line-height:20px;" >'.$i18n['LOG_FILE_ENTRY'].':'.$count.'</b><a style="padding-left: 50px;" title="'.$i18n['cbcontact/ndel'].'" href="load.php?id=cbcontact_form" onClick="return confirmar(this,"'.$count.'","'.$i18n['cbcontact/ndelc'].$count.'. '.$i18n['cbcontact/delsure'].'","log")"><b>X</b></a><br />';
;
foreach($log->children() as $child) {
$name = $child->getName();
echo '<b>'. stripslashes(ucwords($name)) .'</b>: ';
$d = $log->$name;
$n = strtolower($child->getName());
$ip_regex = '/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/';
$url_regex = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
//check if its an url address
if (do_reg($d, $url_regex)) {
$d = '<a href="'. $d .'" target="_blank" >'.$d.'</a>';
}
//check if its an ip address
if (do_reg($d, $ip_regex)) {
if ($d == $_SERVER['REMOTE_ADDR']) {
$d = $i18n['THIS_COMPUTER'].' (<a href="http://www.geobytes.com/IpLocator.htm?GetLocation&IpAddress='. $d.'" target="_blank" >'.$d.'</a>)';
} else {
$d = '<a href="http://www.geobytes.com/IpLocator.htm?GetLocation&IpAddress='. $d.'" target="_blank" >'.$d.'</a>';
}
}
//check if there is an email address
if (check_email_address($d)) {
$d = '<a href="mailto:'.$d.'">'.$d.'</a>';
}
//check if its a date
if ($n === 'date') {
$d = lngDate($d);
}
echo stripslashes(html_entity_decode($d));
echo ' <br />';
}
echo "</p></li>";
$count++;
}
?>
</ol>
<?php
} //END if file_exists
else
{ //If file does not exist
?>
<label><?php echo $i18n['MISSING_FILE']; ?>: ‘<em><?php echo @$log_name; ?></em>’</label>
<?php
}
} // END vermensajes
/* ********************************************** */
/* Function cbcontact_content($content) */
/* */
/* ********************************************** */
function cbcontact_content($content){
////////////////////////////////////////////////////////////////////
// filter content of page searching $cbcontact
////////////////////////////////////////////////////////////////////
/*
echo ' <br>At the very START of function cbcontact_content <br><br>';
echo '\$content at start = '.$content.'<br><br>';
*/
if ( preg_match("/\(%\s*(cbcontact)(\s+(?:%[^%\)]|[^%])+)?\s*%\)/", $content, $coinc)){
$array_coinc = explode(',', $coinc[2]);
$cuantos = count($array_coinc);
array_filter($array_coinc, 'trim_value');
$array_coinc = str_replace("'","",$array_coinc);
$array_coinc = str_replace(" ","",$array_coinc);
if (array_key_exists ('1', $array_coinc) === false) {
$array_coinc[1] = 'true';
} else {
$array_coinc[1] = trim($array_coinc[1]);
}
if (array_key_exists ('2', $array_coinc) === false) {
$array_coinc[2] = 'false';
} else {
$array_coinc[2] = trim($array_coinc[2]);
}
$usus = '';
for ($q = 4; $q < $cuantos; $q++ ){
$usus[$q] = $array_coinc[$q];
}
$usus = str_replace("'","",$usus);
$usus = str_replace(" ","",$usus);
$content_cbcontact = cbcontact_page (trim($array_coinc[0]), $array_coinc[1], $array_coinc[2], false, $usus);
$content = str_replace($coinc[0], $content_cbcontact, $content);
}
return $content;
}
/* *************************************************************************************************** */
/* cbcontact_page() : Main function to output the Contact form, and send the form data as an email */
/* */
/* 1st para : $usu, String, user name of GetSimple admin, or the user's email addr. */
/* 2nd para : $captcha, Boolean, true = Use Captcha, false = Don’t use Captcha, */
/* 3rd para : $sendphpmail, Boolean, true = send mail with PHPMailer class, */
/* false = with the php fn mail() */
/* 4th para : $echocontact, Boolean, true = echo the HTML code for the contact form, */
/* false = return the HTML code */
/* 5th para : $usus .. A String array of users / users' emails */
/* *************************************************************************************************** */
function cbcontact_page($usu, $captcha=true, $sendphpmail=false, $echocontact=true, $usus='') {
global $admin_user_email;
global $SITEURL;
global $SITENAME;
global $LANG;
global $PRETTYURLS;
global $i18n;
global $language;
/* ------------------------------------------------------------------------------------- */
/* Convert passed boolean/strings $captcha, $sendphpmail and $echocontact */
/* to definite booleans. ... These passed in params can be either boolan or string .. */
/* .. So converting to ONLY booleans makes any 'if' code where they are used clearer AND BUG free !*/
/* ------------------------------------------------------------------------------------- */
// Convert $captcha to $captchaboolean
// $captcha -> $captchabool : "1" ->T, "true"->T, "TRUE"->T, "0"->F, "false"->F, "FALSE"->F, ""->F, "Any"->T, true->T, false->F
$captchaboolean = false;
if (($captcha == false) or (strtolower($captcha) == "false"))
{ $captchaboolean = false; }
else
{ $captchaboolean = true; }
// Convert $sendphpmail to $sendphpmailboolean
// $sendphpmail -> $sendphpmailboolean : "1" ->T, "true"->T, "TRUE"->T, "0"->F, "false"->F, "FALSE"->F, ""->F, "Any"->T, true->T, false->F
$sendphpmailboolean = false;
if (($sendphpmail == false) or (strtolower($sendphpmail) == "false"))
{ $sendphpmailboolean = false; }
else
{ $sendphpmailboolean = true; }
// Convert $echocontact to $echocontactboolean
// $echocontact -> $echocontactbool : "1" ->T, "true"->T, "TRUE"->T, "0"->F, "false"->F, "FALSE"->F, ""->F, "Any"->T, true->T, false->F
$echocontactboolean = false;
if (($echocontact == false) or (strtolower($echocontact) == "false"))
{ $echocontactboolean = false; }
else
{ $echocontactboolean = true; }
/* ---------------------------------------- */
/* Define some additional local booleans */
/* ---------------------------------------- */
// -----------------------------------------
// Display success/error message on send, either
// $display_jsalert_boolean = true => In a javascript alert box, or
// $display_jsalert_boolean = false => In the html at the top of the re-output contact form
// -----------------------------------------
$display_jsalert_boolean = true;
// -----------------------------------------
// Define the fields that are required/mandatory/obligatory ..
// $required_fields_all_boolean = true => All contact form fields are required
// $required_fields_all_boolean = false => Only the fields 'Name' and 'Subject' are required
// -----------------------------------------
$required_fields_all_boolean = false;
$log_name = 'cbcontactform.log';
$log_path = GSDATAOTHERPATH.'logs/';
$log_file = $log_path . $log_name;
$fich = return_page_slug();
$idpret = find_url($fich,'');
if ($PRETTYURLS !='') {
$idpret = $idpret.'?';
}
if (file_exists('gsconfig.php')) {
include_once('gsconfig.php');
}
// Debugging
if (defined('GSDEBUG')){
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
} else {
error_reporting(0);
@ini_set('display_errors', 0);
}
//Check session: important for captcha and contact form
if (!isset($_SESSION)) { session_start(); }
// Get the Email address and language defined in the GS admin for the admin user
if (!check_email_address($usu)){
if (file_exists(GSDATAPATH.'users/'.$usu.'.xml')) {
$data = getXML(GSDATAPATH.'users/'.$usu.'.xml');
$admin_user_email = $data->EMAIL;
$LANG = $data->LANG;
}
}
else {
// $value is already/directly a valid email => so assign directly
// to admin_user_email
$admin_user_email = $usu;
$LANG = 'en_US'; // Just a basic default if don't know anything else
}
// i18n compatible
if (isset($_GET['setlang'])){
$LANG = $_GET['setlang']. '_'.strtoupper($_GET['setlang']);
}
if (isset($language)){
switch ($language) {
case 'en':
$LANG = $language. '_US';
break;
default:
$LANG = $language. '_'.strtoupper($language);
break;
}
}
// i18n lang
i18n_merge('cbcontact', $LANG);
// Get the email address of the other users, defined in fn array param $usus
// For each value of $usus if it is an email address, then assign it directly
// to output array $other_user_emails, else assume it is a user name, so get this user's
// email address from the GS admin, and then assign this to $other_user_emails. Note,
// this may not actually be a valid email addr, but assign it anyway .. will
// get an error on send (probably) to highlight the problem .. and the admin
// can correct the email entry in GS admin
// Note, if cbcontact_page() is called from add_filter function cbcontact_content(),
// then if array $usus exists, its first key value is 4, and NOT 0
// Note, the output array other_user_emails will not be created at all, if have no valid email
// directly in usus and none can be found in GS admin. ... so when use other_user_emails
// afterwards test if it first exists with if (isset($other_user_emails))
// $usus is the array (or poss single var) of other users or emails passed to the fn
if ($usus != ''){
// If usus is a single variable, then make into an array .. so can check it also below
if (!(is_array($usus))){
$temp = $usus;
unset($usus);
$usus[4] = $temp;
}
if (is_array($usus)) {
foreach ($usus as $key=> $value) {
if (!check_email_address(trim($value))){
if (file_exists(GSDATAPATH.'users/'.trim($value).'.xml')) {
$data = getXML(GSDATAPATH.'users/'.trim($value).'.xml');
$other_user_emails[$key] = $data->EMAIL;
}
}
else {
// $value is already/directly a valid email => so assign directly
// to other_user_emails
$other_user_emails[$key] = trim($value);
}
} // end for each
}
}
// Initialise error flag/string and message output string
$err = '';
$msgshw = '';
// Define an assoc array fields[] to temporarily hold the user entered textfield values.
// Also used to to re-output textfield for the next displayed HTML contact form.
global $fields;
$fields = array(
i18n_r('cbcontact/Nb') => '', // 'Name',
i18n_r('cbcontact/Em') => '', // 'Email',
i18n_r('cbcontact/Sub') => '', // 'Subject',
i18n_r('cbcontact/Ms') => '', // 'Message',
);
// If we come here becuse the contact form was already displayed and the user hit the
// submit button, then insert the validate fields/send mail script
// Else This is the first time display of the contact form, so just continue ...
if (isset($_POST['contact-submit'])) {
include (GSPLUGINPATH."cbcontact/comprueba.php");
}
?>
<script type="text/javascript">
<!--
function rec_cpt(id,ourl){
var aleat = Math.random();
var mf = document.getElementById(id);
mf.src = ourl + "/cbcontact/&" + aleat;
}
-->
</script>
<?php
//control uri
$request_uri = getenv ("REQUEST_URI"); // Requested URI
//Show in page
$mGSPLUGINPATH = str_replace("\\", "/", GSPLUGINPATH);
$mGSPLUGINPATH = substr($mGSPLUGINPATH, 0, -1);
// -------------------------
// Set up the actual Form HTML
// -----------------------
$cbcontactform = '<form id="cbform" class="" action="'. $idpret.'&tp=contact" method="post">';
// Aldebaran : If option selected, add in a message after a send, will be a success or error message.
if ($display_jsalert_boolean === false) {
if ($msgshw != '') $cbcontactform .= '<div class = "msgshw" >'.$msgshw.'</div>';
else $cbcontactform .= '<div class = "msgshw" > </div>';
}
// Call script to include the main body of he form
include (GSPLUGINPATH.'cbcontact/form/cbcontact.php');
// add in hidden fields
$cbcontactform .= "\r\n\t".'<input type="hidden" name="contact[q_uri]" value="'.$request_uri.'">';
$cbcontactform .= "\r\n\t".'<input type="hidden" name="contact[leaveblank]" value="">';
$cbcontactform .= "\r\n\t".'<input type="hidden" name="contact[leaveso]" value="leaveso">';
$cbcontactform .= "\r\n".'</form>'."\r\n\t";
// ---------------------------------------------------------------------------------------------
// Echo or return the contact form html
//
// $echocontact is passed in as FALSE when cbcontact_page() is called from cbcontact_content()
// so that we return HTML content of $cbcontactform to cbcontact_content() where it is then
// added to $content .. so we replace the page editer entered (% %) syntax with the form code.
//
// $echocontact is passed in as TRUE when we just want to echo the HTML content of $cbcontactform,
// eg when we directly call cbcontact_page() from a template file.
// ---------------------------------------------------------------------------- ------------------
if ($echocontactboolean === true){
echo $cbcontactform;
} else {
return $cbcontactform;
}
}
function trim_value(&$value){
$value = trim($value);
}
?>
cbcontact/comprueba.php :
PHP Code:
<?php
/*****************************************************/
/* Aldebaran Edited Version 1.0 */
/* - An edit of Cumbe's plugin 'Contact Form' v5823 */
/*****************************************************/
//-----------------------------------------------------------------//
//--- comprueba.php: action if form is submit //
//-----------------------------------------------------------------//
if (!isset($_SESSION)) { session_start(); }
if ($captchaboolean === true) {
$imagenCadena = $_SESSION["imagencadena"];
$pot = trim(strtolower($imagenCadena));
}
$server_name = getenv ("SERVER_NAME"); // Server Name
$request_uri = getenv ("REQUEST_URI"); // Requested UR
// check antispam
if (isset($_POST['contact-submit'])) {
if ($_POST['contact']['leaveso'] != 'leaveso' or $_POST['contact']['leaveblank']!=''){
echo '<html>';
echo '<head>';
echo '</head>';
echo '<body>';
echo '<div style="padding: 20px; border: 4px double; margin: 20%;">';
echo i18n_r('cbcontact/spam').'<br />';
echo '<a href="'.$idpret.'">'.i18n_r('cbcontact/back').'</a>';
echo '</div>';
echo '</body>';
echo '</html>';
exit;
}
}
//------------------------
//START CONTACT
//------------------------
if (@$_GET['tp'] == 'contact') {
if (isset($_POST['contact-submit'])) {
// Assign the Forms POST params to the local array $fields[ ]
// Note $_POST['contact'] is an array of all the field values
$fields = $_POST['contact'];
// Just remove any leading/trailing spaces, so if a field just
// contains spaces it is completely emptied, so validated correctly
foreach ( $fields as $key => $value ) {
$fields[$key] = trim($value);
}
// ------------------------------------------ //
// Do field validation //
// ------------------------------------------ //
$err = '';
// Check captcha - mandatory, if enabled. Note $pot = value of $imagenCadena
if ($captchaboolean === true) {
if ( $pot != trim(strtolower($fields['pot']))) {
$err = i18n_r('cbcontact/MSG_CAPTCHA_FAILED');
$err .= ' Captcha code: '.$pot.', Code wrote: '.$fields['pot'];
}
}
// if err != '' due to Captca err then don't do any more validating
if ($err == '') {
// Check all fields, mandatory or not ..
// Check in reverse order so first see the error message of top most field
// ------------------------------------------------------
// Check MESSAGE - If empty, label, (*)label then empty, and (Is mandatory) so then set err msg
if ( ($fields[i18n_r('cbcontact/Ms')] == '' ) or
($fields[i18n_r('cbcontact/Ms')] == '(*)'.i18n_r('cbcontact/Ms')) or
($fields[i18n_r('cbcontact/Ms')] == i18n_r('cbcontact/Ms'))
)
{
$fields[i18n_r('cbcontact/Ms')] = '';
$err = i18n_r('cbcontact/Ms'). ' : *** '.i18n_r('cbcontact/Co').' ***';
}
// Check SUBJECT - If empty, label, (*)label then empty, and If mandatory then set err msg
if ( ($fields[i18n_r('cbcontact/Sub')] == '' ) or
($fields[i18n_r('cbcontact/Sub')] == '(*)'.i18n_r('cbcontact/Sub')) or
($fields[i18n_r('cbcontact/Sub')] == i18n_r('cbcontact/Sub'))
)
{
$fields[i18n_r('cbcontact/Sub')] = '';
if ($required_fields_all_boolean === true) { $err = i18n_r('cbcontact/Sub'). ' : *** '.i18n_r('cbcontact/Co').' ***'; }
}
// Check EMAIL - If empty, label, (*)label then empty, and (Is mandatory) so then set err msg
if ( ($fields[i18n_r('cbcontact/Em')] == '' ) or
($fields[i18n_r('cbcontact/Em')] == '(*)'.i18n_r('cbcontact/Em')) or
($fields[i18n_r('cbcontact/Em')] == i18n_r('cbcontact/Em'))
)
{
$fields[i18n_r('cbcontact/Em')] = '';
$err = i18n_r('cbcontact/Em'). ' : *** '.i18n_r('cbcontact/Co').' ***';
}
// Check NAME - If empty, label, (*)label then empty, andIf mandatory then set err msg
if ( ($fields[i18n_r('cbcontact/Nb')] == '' ) or
($fields[i18n_r('cbcontact/Nb')] == '(*)'.i18n_r('cbcontact/Nb')) or
($fields[i18n_r('cbcontact/Nb')] == i18n_r('cbcontact/Nb'))
)
{
$fields[i18n_r('cbcontact/Nb')] = '';
if ($required_fields_all_boolean === true) { $err = i18n_r('cbcontact/Nb'). ' : *** '.i18n_r('cbcontact/Co').' ***'; }
}
} // END check the 4 text fields
// Validate done .. If $err still empty, then all OK, else $err contains the err msg
// Also, for any field, mandatory or not, if they had a reminder label in them
// then these should now be empty (if had no captach error)
// Also just assign the 4 main fields to simple local variables, just for convenience
$field_fromName = stripslashes(html_entity_decode($fields[i18n_r('cbcontact/Nb')]));
$field_fromEmail = stripslashes(html_entity_decode($fields[i18n_r('cbcontact/Em')]));
$field_subject = stripslashes(html_entity_decode($fields[i18n_r('cbcontact/Sub')]));
$field_message = stripslashes(html_entity_decode($fields[i18n_r('cbcontact/Ms')]));
// If No error then prepare mail for send ...
if ($err == '') {
// Build the Body of the mail from the 4 contact form fields, ´plus ip address etc
// ----------------------------------------------
$body = '"'.$field_subject.'": <a href="'.substr($idpret,0,-1).'">'.substr($idpret,0,-1).'</a>';
$body .= "<hr><br />";
if ( ! file_exists($log_file) ) {
$xml = new SimpleXMLExtended('<channel></channel>');
} else {
$xmldata = file_get_contents($log_file);
$xml = new SimpleXMLExtended($xmldata);
}
$thislog = $xml->addChild('entry');
$thislog->addChild('date', date('r'));
$cdata = $thislog->addChild('captcha');
$cdata->addCData($captcha);
$cdata = $thislog->addChild('ip_address');
$ip = getenv("REMOTE_ADDR");
$cdata->addCData(htmlentities($ip, ENT_QUOTES, 'UTF-8'));
$body .= "Ip: ". $ip ."<br />";
unset($fields['pot']);
unset($fields['contact-submit']);
unset($fields['submit']);
unset($fields['leaveso']);
unset($fields['leaveblank']);
foreach ( $fields as $key => $value ) {
if (substr($key, 0, 2) != 'q_') {
$body .= ucfirst($key) .": ". stripslashes(html_entity_decode($value, ENT_QUOTES, 'UTF-8')) ."<br />";
$cdata = $thislog->addChild(clean_url($key));
$cdata->addCData(stripslashes(html_entity_decode($value, ENT_QUOTES, 'UTF-8')));
}
}
XMLsave($xml, $log_file);
// *************************************************************** //
// Send the mail .. with the PHP mail() fn or the PHPMailer class //
// *************************************************************** //
if ($sendphpmailboolean === false)
{
// ****************************************** //
// Send the mail .. with the PHP mail() fn //
// ****************************************** //
$headers = "From: ".$field_fromEmail."\r\n";
$headers .= "Return-Path: ".$field_fromEmail."\r\n";
$headers .= "Content-type: text/html; charset=UTF-8 \r\n";
$result = mail($admin_user_email, $field_subject, $body, $headers);
if ($result == false) { $err = "".i18n_r('cbcontact/MSG_guestERR')." <br>";}
if (isset($other_user_emails)) {
foreach ($other_user_emails as $key=>$value){
$result = mail($value, $field_subject, $body, $headers);
if ($result == false) { $err = "".i18n_r('cbcontact/MSG_guestERR')." <br>";}
}
}
}
else // $sendphpmailboolean = true
{
// ****************************************** //
// Send the mail .. with PHPMailer //
// ****************************************** //
if (is_dir(GSPLUGINPATH.'PHPMailer_v5.1') and file_exists(GSPLUGINPATH.'PHPMailer_v5.1/class.phpmailer.php')){
require(GSPLUGINPATH.'PHPMailer_v5.1/class.phpmailer.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->CharSet = "utf-8";
$mail->SMTPDebug = false; // enables SMTP debug information (for testing)
// false = disabled debug
// 1 = errors and messages
// 2 = messages only
// set mailer to use SMTP
$mail->IsSMTP();
// Uncomment this if you need ssl
$mail->SMTPSecure = ""; // "ssl";
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "localhost"; // specify SMTP Server name
$mail->Port = 25; // specify SMTP Server port number, default 25
$mail->SMTPAuth = true; // turn on SMTP authentication
// When sending email using PHPMailer, you need to use a valid email address
// - username/password
$mail->Username = "me@myusername.com"; // SMTP username (dummy)
$mail->Password = "mypassword"; // SMTP password (dummy)
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
// Set the From email address
$mail->From = $field_fromEmail; // The From email address - Form field 'Email'
$mail->FromName = $field_fromName; // Form field 'Name' => The name seen outside the < > of the From email address
$mail->Subject = $field_subject; // Form field 'Subject'
// Assign the email body $body, created above
$myBody = $body;
$mail->Body = $myBody; // Form field 'Message'
$mail->AltBody = $myBody; // Body for non-HTML mail clients .. so should be in plain text, here not
$ex = null;
try {
// Add the TO email address of the GS admin user, and the
// TO email addresses $other_user_emails of the passed in users $usus
$mail->AddAddress($admin_user_email,"");
// echo "Email added : ".$admin_user_email."<br/>";
if (isset($other_user_emails)) {
foreach ($other_user_emails as $key=>$value){
$mail->AddAddress($value,"");
// echo "Email added : ".$value."<br/>";
}
}
// Add a ReplyTo email address
$mail->addReplyTo($field_fromEmail, $field_fromName);
// Actually send the email
$mail->Send();
}
catch (phpmailerException $ex){
$err = "".i18n_r('cbcontact/MSG_guestERR')." <br>";
$err .= "Mailer Error: ". $mail->ErrorInfo;
}
catch (Exception $ex){
$err = "".i18n_r('cbcontact/MSG_guestERR')." <br>";
$err .= "Mailer Error: ". $mail->ErrorInfo;
}
} // End else if dir PHPMailer_v5.1 exists etc
else {
// Developer/ plugin user message .. Folder PHPMailer_v5.1 does not exist
$err = strtoupper(i18n_r('cbcontact/errphphmail'))."<br/>";
}
} // End if (validation) ($err == '')
// ----------------------------------------- //
// END Send the mail with PHP mailer //
// ----------------------------------------- //
} // End if/else sendphpmailboolean
// Display success/error message on send, either as a js alert or directly in contact form
if ($display_jsalert_boolean === true) {
if ($err == '') { $msgshw = i18n_r('cbcontact/MSG_CONTACTSUC'); } // success
else { $msgshw = $err; }
?>
<script type="text/javascript">
<!--
alert ("<?php echo $msgshw; ?>");
-->
</script>
<?php
}
else { // Display inline above contact form ( $msgshw output in form html at bottom of cbcontact_form.php)
// If a success message colour text blue,
// if an error message color text red
if ($err == '') {
$msgshw = '<div style="color:blue">'.i18n_r('cbcontact/MSG_CONTACTSUC').'</div>'; // success
}
else {
$msgshw = '<div style="color:red">'.$err.'</div>';
}
}
// Re-assign array $fields[] as necessary ... $fields[] is used to reassign the text fields
// of the next displayed HTML contact form. So ...
// If $err empty, then we had no validation error nor send error, and msg should have been sent =>
// So then assign $fields[] empty, ready so user can send another message
// Note, a form textfield is shown with the label text, as a reminder, but this
// is done directly in the final form creation script cbcontact.php, and not in the variable fields[]
// IF $err is NOT empty, then we had a validation error or had a send problem =>
// So then just leave $fields[] with the values already entered by User,
// .. .. so user does not have to re-enter the good fields, and can
// correct the (poss) erroneous fields
if($err == '') {
$fields[i18n_r('cbcontact/Nb')] = ''; // 'Name'
$fields[i18n_r('cbcontact/Em')] = ''; // 'Email'
$fields[i18n_r('cbcontact/Sub')] = ''; // 'Subject'
$fields[i18n_r('cbcontact/Ms')] = ''; // 'Message'
}
}
}
?>
cbcontact/form/cbcontact.php :
PHP Code:
<?php
/*****************************************************/
/* Aldebaran Edited Version 1.0 */
/* - An edit of Cumbe's plugin 'Contact Form' v5823 */
/*****************************************************/
// NAME Input field
// ------------------
if ($required_fields_all_boolean === true) {
$cbcontactform .= '<input class="cbrightV" type="text" onblur="if (this.value == "") {this.value = "(*)'.i18n_r('cbcontact/Nb').'"}" onfocus="if(this.value == "(*)'.i18n_r('cbcontact/Nb').'") {this.value = ""}" value="';
if ($fields[i18n_r('cbcontact/Nb')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Nb')];
} else {
$cbcontactform .= '(*)'.i18n_r('cbcontact/Nb');
}
$cbcontactform .= '" name="contact['.i18n_r('cbcontact/Nb').']">';
}
else {
$cbcontactform .= '<input class="cbrightV" type="text" onblur="if (this.value == "") {this.value = "'.i18n_r('cbcontact/Nb').'"}" onfocus="if(this.value == "'.i18n_r('cbcontact/Nb').'") {this.value = ""}" value="';
if ($fields[i18n_r('cbcontact/Nb')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Nb')];
} else {
$cbcontactform .= i18n_r('cbcontact/Nb');
}
$cbcontactform .= '" name="contact['.i18n_r('cbcontact/Nb').']">';
}
// EMAIL Input field
// -------------------
$cbcontactform .= '<input class="cbrightV" type="text" onblur="if (this.value == "") {this.value = "(*)'.i18n_r('cbcontact/Em').'"}" onfocus="if(this.value == "(*)'.i18n_r('cbcontact/Em').'") {this.value = ""}" value="';
if ($fields[i18n_r('cbcontact/Em')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Em')];
} else {
$cbcontactform .= '(*)'.i18n_r('cbcontact/Em');
}
$cbcontactform .= '" name="contact['.i18n_r('cbcontact/Em').']">';
// SUBJECT Input field
// ---------------------
if ($required_fields_all_boolean === true) {
$cbcontactform .= '<input class="cbrightV" type="text" onblur="if (this.value == "") {this.value = "(*)'.i18n_r('cbcontact/Sub').'"}" onfocus="if(this.value == "(*)'.i18n_r('cbcontact/Sub').'") {this.value = ""}" value="';
if ($fields[i18n_r('cbcontact/Sub')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Sub')];
} else {
$cbcontactform .= '(*)'.i18n_r('cbcontact/Sub');
}
$cbcontactform .= '" name="contact['.i18n_r('cbcontact/Sub').']">';
}
else {
$cbcontactform .= '<input class="cbrightV" type="text" onblur="if (this.value == "") {this.value = "'.i18n_r('cbcontact/Sub').'"}" onfocus="if(this.value == "'.i18n_r('cbcontact/Sub').'") {this.value = ""}" value="';
if ($fields[i18n_r('cbcontact/Sub')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Sub')];
} else {
$cbcontactform .= i18n_r('cbcontact/Sub');
}
$cbcontactform .= '" name="contact['.i18n_r('cbcontact/Sub').']">';
}
// MESSAGE Input field
// ----------------------
$cbcontactform .= '<textarea class="cbrightV" onblur="if (this.value == "") {this.value = "(*)'.i18n_r('cbcontact/Ms').'"}" onfocus="if(this.value == "(*)'.i18n_r('cbcontact/Ms').'") {this.value = ""}" name="contact['.i18n_r('cbcontact/Ms').']">';
if ($fields[i18n_r('cbcontact/Ms')] != "") {
$cbcontactform .= $fields[i18n_r('cbcontact/Ms')];
} else {
$cbcontactform .= '(*)'.i18n_r('cbcontact/Ms');
}
$cbcontactform .= '</textarea>';
// system captcha - mandatory, if enabled.
// -------------------------------------
if ($captchaboolean === true) {
// This block a) text /rl = 'If you can\'t see the code clearly click Reload'
// b) captch image
// c) reload button
$cbcontactform .= '<div class="cbcaptcha">';
$cbcontactform .= '<div class="cbcaptcha_label">'.i18n_r('cbcontact/veri').' <span class="cbreload_label"> '.i18n_r('cbcontact/rl').'</span></div>';
$cbcontactform .= '<div>';
$cbcontactform .= '<img id="captcha" class="cbcaptchaimg" src="'.$SITEURL.'plugins/cbcontact/img_cpt.php?url='.GSPLUGINPATH.'cbcontact/" alt=" " />';
$cbcontactform .= '<input class="cbreload" type="button" value="'.i18n_r('cbcontact/rl_but').'" onClick="javascript:rec_cpt("captcha","'.$SITEURL.'plugins/cbcontact/img_cpt.php?url='.$mGSPLUGINPATH.'")" />';
$cbcontactform .= '</div>';
$cbcontactform .= '</div>';
// This block a) text (*) + text /Cpt = 'Copy the CAPTCHA Code','
// b) input field captcha name="contact[pot]"
// c) send button
// d) text (*) + text /Rf = 'Required fields',
$cbcontactform .= '<div class="cbpadleft">';
$cbcontactform .= '<div class="cbcaptcha_write"> (*)'.i18n_r('cbcontact/Cpt').'</div>';
$cbcontactform .= '<input class="cbcaptcha_input" type="text" value="" name="contact[pot]" />';
$cbcontactform .= '<input class="cbsend" type="submit" value="'.i18n_r('cbcontact/Ev').'" id="contact-submit" name="contact-submit" />';
$cbcontactform .= '<div class="cbreload_label">(*) '.i18n_r('cbcontact/Rf').'</div>';
$cbcontactform .= '</div>';
} // End if ($captchaboolean === true)
else { // Else $captchaboolean is false
// This block a) send button
// b) text (*) + text /Rf = 'Required fields',
$cbcontactform .= '<div class="cbpadleft">';
$cbcontactform .= '<input class="cbsend" type="submit" value="'.i18n_r('cbcontact/Ev').'" id="contact-submit" name="contact-submit" />';
$cbcontactform .= '<div class="cbreload_label">(*) '.i18n_r('cbcontact/Rf').'</div>';
$cbcontactform .= '</div>';
} // End if ELSE ($captchaboolean === true)
?>
cbcontact/form/cbcontact.css
(not really necessary, just to improve display ) :
PHP Code:
/*****************************************************/
/* Aldebaran Edited Version 1.0 */
/* - An edit of Cumbe's plugin 'Contact Form' v5823 */
/*****************************************************/
#cbform {
color: #555555;
font-family: Arial,Helvetica,sans-serif;
width: 100%;
}
#cbform .noshow { display: none; }
#cbform .cbright {
border-radius: 6px;
-moz-border-radius:6px;
-khtml-border-radius:6px;
-webkit-border-radius:6px;
/*-o-border-radius:6px;*/
border-style: inset;
font-size: 14px;
margin-bottom: 6px;
margin-left: 5px;
padding: 5px;
width: 400px;
}
#cbform .cbrightV {
border-radius: 6px;
-moz-border-radius:6px;
-khtml-border-radius:6px;
-webkit-border-radius:6px;
/*-o-border-radius:6px;*/
border-style: inset;
color: #555555;
font-family: Arial,Helvetica,sans-serif;
font-size: 14px;
margin-bottom: 6px;
margin-left: 0px; /* Aldebaran : was 90px */
padding: 5px;
width: 300px; /* Aldebaran : was 400px */
border:1px solid #808080; /* Aldebaran : new */
}
#cbform .cbradio {
margin-left: 15px;
vertical-align: middle;
}
#cbform .cbcheck {
margin-left: 15px;
vertical-align: middle;
}
#cbform textarea {
border-radius: 6px;
-moz-border-radius:6px;
-khtml-border-radius:6px;
-webkit-border-radius:6px;
height: 100px;
}
#cbform .cbcaptcha {
padding-left: 0px; /* Aldebaran : was 90px */
width: 300px; /* Aldebaran : was 400px */
}
#cbform .cbcaptcha .cbcaptchaimg {
border: 2px outset #CCCCCC;
margin: 0 15px 10px 0;
vertical-align: middle;
}
#cbform .cbcaptcha_label {
font-size: 16px;
width: 390px;
margin-top: 5px;
}
#cbform .cbcaptcha_input {
border-radius: 6px;
-moz-border-radius: 6px;
-khtml-border-radius: 6px;
-webkit-border-radius: 6px;
border-style: inset;
font-size:20px;
margin: 0 15px 0 0;
padding: 5px;
text-align: center;
vertical-align: middle;
width: 164px;
border:1px solid #808080; /* Aldebaran : new */
}
#cbform .cbcaptcha_write {
font-size: 12px;
font-style: italic;
margin-top: -5px;
}
#cbform .cbreload, .cbsend {
background-color: #DEDEDE;
border-radius: 6px;
-moz-border-radius:6px;
-khtml-border-radius:6px;
-webkit-border-radius:6px;
border-style: outset;
color: #444444;
font-size: 18px;
padding: 3px 0;
vertical-align: top;
width: 100px; }
#cbform .cbreload:hover, .cbsend:hover {
background-color: #EEEEEE;
border-style: inset;
}
#cbform .cbreload_label {
font-size: 11px;
font-style: italic; }
#cbform .cbpadleft {
padding-left: 0px; /*was 90px */
}
/* Aldebaran new */
#cbform .msgshw {
padding-bottom: 10px;
}