Submit a Feature Idea for Consideration

$sendFormTo = 'areilly@ur.rutgers.edu';
$siteEmail = 'noreply@rutgers.edu';
$emailSubject = 'Submission: Feature Idea for Consideration';

$requiredFields = array('name', 'title', 'phone', 'feat_name', 'feat_campus', 'feat_school', 'feat_phone', 'feat_about', 'submit');

$elements = array();

// Form Fields
$fields['name']['label'] = 'Contact Name:';
$fields['name']['error'] = false;
$fields['title']['label'] = 'Title:';
$fields['title']['error'] = false;
$fields['school']['label'] = 'School/Unit:';
$fields['school']['error'] = false;
$fields['email']['label'] = 'Email:';
$fields['email']['error'] = false;
$fields['phone']['label'] = 'Phone:';
$fields['phone']['error'] = false;
$fields['feat_name']['label'] = 'Name of the Person or Event to Be Featured:';
$fields['feat_name']['error'] = false;
$fields['feat_campus']['label'] = 'Campus:';
$fields['feat_campus']['error'] = false;
$fields['feat_school']['label'] = 'School/Unit:';
$fields['feat_school']['error'] = false;
$fields['feat_dept']['label'] = 'Department:';
$fields['feat_dept']['error'] = false;
$fields['feat_phone']['label'] = 'Phone:';
$fields['feat_phone']['error'] = false;
$fields['feat_email']['label'] = 'Email:';
$fields['feat_email']['error'] = false;
$fields['feat_site']['label'] = 'Website:';
$fields['feat_site']['error'] = false;
$fields['feat_about']['label'] = 'Tell us about your feature idea:';
$fields['feat_about']['error'] = false;

if (isset($_POST)) {
$errorDetectionFlag = false;
$counter = 0;
//== INITIALIZE $elements VAR
foreach ($_POST as $key=>$value) {
$counter++;

$elements[$key] = htmlspecialchars($value);

if (in_array($key, $requiredFields)) {

$value = trim ($value);

if (empty($value)) {
$errorDetectionFlag = true;
$fields[$key]['error'] = true;
}

}
}
//== END INITIALIZE

// == VALIDATE EMAIL ADDRESS
if (!empty($elements['feat_email'])) {

if (!valid_email_address($elements['feat_email'])) {
$errorDetectionFlag = true;
$fields['feat_email']['error'] = true;
}

}

if (!empty($elements['email'])) {

if (!valid_email_address($elements['email'])) {
$errorDetectionFlag = true;
$fields['email']['error'] = true;
}

}
// == END EMAIL VALIDATION

if ($counter >= sizeof($requiredFields)) {
if ($errorDetectionFlag === false) {
// If no errors found process form data through email

processFormSubmit($sendFormTo, $siteEmail, $emailSubject );

}
}
}

function processFormSubmit($to, $from, $subject) {

$NL = "\r\n";

$contactEmailAddress = false;
$message = "";
if (isset($_POST['name'])) {
$message .= "Contact Name: ". $_POST['name'] . $NL;
}
if (isset($_POST['title'])) {
$message .= "Title: ". $_POST['title'] . $NL;
}
if (isset($_POST['school'])) {
$message .= "School/Unit: ". $_POST['school'] . $NL;
}
if (isset($_POST['email'])) {
$message .= "Email: ". $_POST['email'] . $NL;
$contactEmailAddress = $_POST['email'];
}
if (isset($_POST['phone'])) {
$message .= "Phone: ". $_POST['phone'] . $NL;
}
if (isset($_POST['feat_name'])) {
$message .= "Name of the Person or Event to Be Featured: ". $_POST['feat_name'] . $NL;
}
if (isset($_POST['feat_campus'])) {
$message .= "Campus: ". $_POST['feat_campus'] . $NL;
}
if (isset($_POST['feat_school'])) {
$message .= "School/Unit: ". $_POST['feat_school'] . $NL;
}

if (isset($_POST['feat_dept'])) {
$message .= "Department: ". $_POST['feat_dept'] . $NL;
}
if (isset($_POST['feat_phone'])) {
$message .= "Phone: ". $_POST['feat_phone'] . $NL;
}
if (isset($_POST['feat_email'])) {
$message .= "Email: ". $_POST['feat_email'] . $NL;
}
if (isset($_POST['feat_site'])) {
$message .= "Website: ". $_POST['feat_site'] . $NL;
}
if (isset($_POST['feat_about'])) {
$message .= "Tell us about your feature idea: ". $_POST['feat_about'] . $NL;
}

if (!empty($contactEmailAddress)) {
$from = $contactEmailAddress;
}

$s = sendEmail($message, $to, $from, $subject);

drupal_set_message ($s);

}

function sendEmail($msg, $to, $from, $subject) {
$NL = "\r\n";

//create a boundary string. It must be unique
$mime_boundary = md5(date('r', time()));

// Headers
//define the headers we want passed. Note that they are separated with $N
$headers = "From: {$from}" . $NL;
$headers .= "Reply-To: {$from}" . $NL;
$headers .= "MIME-Version: 1.0" . $NL;
$headers .= "Content-Type: multipart/alternative; ";
$headers .= 'boundary="PHP-alt-'.$mime_boundary.'"';

//define the body of the message.
// Use our boundary string to create plain text and HTML versions
$message = "--PHP-alt-{$mime_boundary}" . $NL;
$message .= 'Content-Type: text/plain; charset="iso-8859-1"' . $NL;
$message .= "Content-Transfer-Encoding: 7bit ". $NL . $NL;

$message .= $msg. $NL . $NL;

$message .= "--PHP-alt-{$mime_boundary}" . $NL;
$message .= 'Content-Type: text/html; charset="iso-8859-1"' . $NL;
$message .= "Content-Transfer-Encoding: 7bit" . $NL . $NL;
$message .= nl2br($msg) . $NL . $NL;

$message .= "--PHP-alt-{$mime_boundary}--";

//mail($to,$subject,$message,"From:$from\r\nReply-to: $from\r\nContent-type: text/html; charset=us-ascii");

// Send the message
if(!mail($to, $subject, $message, $headers))
{
// If the mail function fails, return an error message
return "Something went wrong!";
}
else
{
// Return a success message if nothing went wrong
return "Message sent successfully.";
}

}

function getValue($elements, $field, $trimmed=false) {

if (isset($elements[$field])) {

$value = $elements[$field];

if ($trimmed === true) {
$value = trim($value);
}

return $value;
}
return '';
}

function fieldLabel($fields, $element) {
$styleClass = "";

if (isset($fields[ $element ]['error'])) {

if ($fields[ $element ]['error'] === true) {

$styleClass = ' style="color: red;" ';
}
}

if (isset($fields[ $element ]['label'])) {

echo "";
echo $fields[ $element ]['label'];
echo '
';
}

}

if (!function_exists('valid_email_address')) {
function valid_email_address($mail) {
$user = '[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+';
$domain = '(?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+';
$ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}';
$ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}';

return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail);
}
}

?>

(*) Indicates a required field.
 
Submitter’s Information
*
*
*
   
About the Feature Idea
*
*
*
*
*