1
0
mirror of https://github.com/e107inc/e107.git synced 2025-06-05 02:15:13 +02:00

Contact form is now more flexible, allowing for custom fields in the template and customization of the email subject.

This commit is contained in:
Cameron 2015-08-17 11:22:24 -07:00
parent d19906944b
commit ec5db40d67
6 changed files with 81 additions and 22 deletions

View File

@ -14,7 +14,9 @@ require_once("class2.php");
//define('e_HANDLER', "e107_handlers/");
// security image may be disabled by removing the appropriate shortcodes from the template.
$active = varset($pref['contact_visibility'], e_UC_PUBLIC);
if(!check_class($active))
$contactInfo = trim(SITECONTACTINFO);
if(!check_class($active) && empty($contactInfo))
{
e107::getRedirect()->go(e_HTTP."index.php");
}
@ -53,11 +55,12 @@ if(isset($_POST['send-contactus']))
$error = "";
$sender_name = $tp->toEmail($_POST['author_name'],TRUE,'RAWTEXT');
$sender = check_email($_POST['email_send']);
$subject = $tp->toEmail($_POST['subject'],TRUE,'RAWTEXT');
$body = $tp->toEmail($_POST['body'],TRUE,'RAWTEXT');
$sender_name = $tp->toEmail($_POST['author_name'], true,'RAWTEXT');
$sender = check_email($_POST['email_send']);
$subject = $tp->toEmail($_POST['subject'], true,'RAWTEXT');
$body = $tp->toEmail($_POST['body'], true,'RAWTEXT');
$email_copy = !empty($_POST['email_copy']) ? 1 : 0;
// Check Image-Code
if (isset($_POST['rand_num']) && !$sec_img->verify_code($_POST['rand_num'], $_POST['code_verify']))
@ -66,25 +69,26 @@ if(isset($_POST['send-contactus']))
}
// Check message body.
if(strlen(trim($_POST['body'])) < 15)
if(strlen(trim($body)) < 15)
{
$error .= LANCONTACT_12."\\n";
}
// Check subject line.
if(varset($_POST['subject']) && strlen(trim($_POST['subject'])) < 2)
if(strlen(trim($subject)) < 2)
{
$error .= LANCONTACT_13."\\n";
}
if(!strpos(trim($_POST['email_send']),"@"))
if(!strpos(trim($sender),"@"))
{
$error .= LANCONTACT_11."\\n";
}
// Check email address on remote server (if enabled).
// Check email address on remote server (if enabled). XXX Problematic!
/*
if ($pref['signup_remote_emailcheck'] && $error == '')
{
require_once(e_HANDLER."mail_validation_class.php");
@ -101,6 +105,7 @@ if(isset($_POST['send-contactus']))
}
}
*/
// No errors - so proceed to email the admin and the user (if selected).
if(empty($error))
@ -145,6 +150,38 @@ if(isset($_POST['send-contactus']))
}
// ----------------------
$CONTACT_EMAIL = e107::getCoreTemplate('contact','email');
unset($_POST['contact_person'], $_POST['author_name'], $_POST['email_send'] , $_POST['subject'], $_POST['body'], $_POST['rand_num'], $_POST['code_verify'], $_POST['send-contactus']);
if(!empty($_POST)) // support for custom fields in contact template.
{
foreach($_POST as $k=>$v)
{
$body .= $k.":\t".$tp->toEmail($v, true,'RAWTEXT')."\n";
}
}
if(!empty($CONTACT_EMAIL['subject']))
{
$vars = array('CONTACT_SUBJECT'=>$subject,'CONTACT_PERSON'=>$send_to_name);
if(!empty($_POST)) // support for custom fields in contact template.
{
foreach($_POST as $k=>$v)
{
$scKey = strtoupper($k);
$vars[$scKey] =$tp->toEmail($v, true,'RAWTEXT');
}
}
$subject = $tp->simpleParse($CONTACT_EMAIL['subject'],$vars);
}
// -----------------------
// Send as default sender to avoid spam issues. Use 'replyto' instead.
$eml = array(
'subject' => $subject,
@ -155,11 +192,12 @@ if(isset($_POST['send-contactus']))
'template' => 'default'
);
$message = e107::getEmail()->sendEmail($send_to, $send_to_name, $eml, false) ? LANCONTACT_09 : LANCONTACT_10;
// $message = (sendemail($send_to,"[".SITENAME."] ".$subject, $body,$send_to_name,$sender,$sender_name)) ? LANCONTACT_09 : LANCONTACT_10;
if(isset($pref['contact_emailcopy']) && $pref['contact_emailcopy'] && $_POST['email_copy'] == 1)
if(isset($pref['contact_emailcopy']) && $pref['contact_emailcopy'] && $email_copy == 1)
{
require_once(e_HANDLER."mail.php");
sendemail($sender,"[".SITENAME."] ".$subject, $body,ADMIN,$sender,$sender_name);
@ -184,23 +222,35 @@ if(SITECONTACTINFO)
$CONTACT_INFO = e107::getCoreTemplate('contact','info');
}
$text = $tp->parseTemplate($CONTACT_INFO, TRUE, vartrue($contact_shortcodes));
$text = $tp->parseTemplate($CONTACT_INFO, true, vartrue($contact_shortcodes));
$ns -> tablerender(LANCONTACT_01, $text,"contact");
}
if(isset($pref['sitecontacts']) && $pref['sitecontacts'] != 255)
if(check_class($active) && isset($pref['sitecontacts']) && $pref['sitecontacts'] != e_UC_NOBODY)
{
$contact_shortcodes = e107::getScBatch('contact');
// Wrapper support
$contact_shortcodes->wrapper('contact/form');
$text = $tp->parseTemplate($CONTACT_FORM, TRUE, $contact_shortcodes);
$text = $tp->parseTemplate($CONTACT_FORM, true, $contact_shortcodes);
if(trim($text) != "")
{
$ns -> tablerender(LANCONTACT_02, $text, "contact");
}
}
elseif($active == e_UC_MEMBER && ($pref['sitecontacts'] != e_UC_NOBODY))
{
$srch = array("[","]");
$repl = array("<a class='alert-link' href='".e_SIGNUP."'>","</a>");
$message = LANCONTACT_16; // "You must be [registered] and signed-in to use this form.";
$ns -> tablerender(LANCONTACT_02, "<div class='alert alert-info'>".str_replace($srch, $repl, $message)."</div>", "contact");
}
require_once(FOOTERF);
exit;
?>

View File

@ -601,10 +601,10 @@ $text .= "<fieldset class='e-hideme' id='core-prefs-email'>
</td>
</tr>
<tr>
<td><label for='contact_visibility'>Contact Page Visibility</label></td>
<td><label for='contact_visibility'>Contact Form Visibility</label></td>
<td>
".$e_userclass->uc_dropdown('contact_visibility', varset( $pref['contact_visibility'],e_UC_PUBLIC), null, "tabindex='".$frm->getNext()."'")."
<div class='smalltext field-help'>Contact information and/or form will only be visible to this userclass group.</div>
<div class='smalltext field-help'>Contact form will only be visible to this userclass group.</div>
</td>
</tr>
<tr>

View File

@ -90,7 +90,9 @@ class contact_shortcodes extends e_shortcode
function sc_contact_name($parm='')
{
return "<input type='text' style='max-width:99%' id='contactName' title='Your full name' name='author_name' required='required' size='30' class='tbox form-control' value=\"".varset($_POST['author_name'])."\" />";
$userName = deftrue('USERNAME');
return "<input type='text' style='max-width:99%' id='contactName' title='Your full name' name='author_name' required='required' size='30' class='tbox form-control' value=\"".varset($_POST['author_name'],$userName)."\" />";
}
@ -98,7 +100,10 @@ class contact_shortcodes extends e_shortcode
function sc_contact_email($parm='')
{
return "<input type='email' style='max-width:99%' id='contactEmail' title='a valid email address' name='email_send' required='required' size='30' class='tbox form-control' value='".(vartrue($_POST['email_send']) ? $_POST['email_send'] : USEREMAIL)."' />";
$userEmail = deftrue('USEREMAIL');
$disabled = (!empty($userEmail)) ? 'readonly' : ''; // don't allow change from a verified email address.
return "<input type='email' style='max-width:99%' ".$disabled." id='contactEmail' title='a valid email address' name='email_send' required='required' size='30' class='tbox form-control' value='".(vartrue($_POST['email_send']) ? $_POST['email_send'] : USEREMAIL)."' />";
}

View File

@ -65,7 +65,6 @@ $CONTACT_TEMPLATE['menu'] = '
$CONTACT_WRAPPER['form']['CONTACT_EMAIL_COPY'] = "<tr><td>{---}".LANCONTACT_07."</td></tr>";
$CONTACT_WRAPPER['form']['CONTACT_PERSON'] = "<tr><td>".LANCONTACT_14."<br />{---}</td></tr>";
//FIXME Upgrade to bootstrap3 non-table format for phone/tablet compatibility.
$CONTACT_TEMPLATE['form'] = "
<form action='".e_SELF."' method='post' id='contactForm' >
<table class='table'>
@ -87,14 +86,17 @@ $CONTACT_TEMPLATE['menu'] = '
</td></tr>
{CONTACT_IMAGECODE}
{CONTACT_IMAGECODE_INPUT}
<tr><td>
{CONTACT_SUBMIT_BUTTON}
</td></tr>
</table>
</form>";
// Customize the email subject
// Variables: CONTACT_SUBJECT and CONTACT_PERSON as well as any custom fields set in the form. )
$CONTACT_TEMPLATE['email']['subject'] = "{CONTACT_SUBJECT}";
?>

View File

@ -32,4 +32,6 @@ define("LANCONTACT_13", "Please include a subject.");
define("LANCONTACT_14", "Send message to:");
define("LANCONTACT_15", "Incorrect code entered");
define("LANCONTACT_16", "You must be [registered] and signed-in to use this form.");

View File

@ -53,7 +53,7 @@ class membersonly
if (intval($pref['user_reg'])===1)
{
$srch = array("[","]");
$repl = array("<a href='".e_SIGNUP."'>","</a>");
$repl = array("<a class='alert-link' href='".e_SIGNUP."'>","</a>");
return str_replace($srch,$repl, LAN_MEMBERS_3);
}
@ -72,7 +72,7 @@ class membersonly
function sc_membersonly_login()
{
$srch = array("[","]");
$repl = array("<a href='".e_LOGIN."'>","</a>");
$repl = array("<a class='alert-link' href='".e_LOGIN."'>","</a>");
return str_replace($srch,$repl, LAN_MEMBERS_2);
}