Gix075 / ajax-contact-form

An easy to use and hightly customizable Ajax Contact Form, including inputs validation and Google ReCaptcha.
MIT License
6 stars 1 forks source link

Adding new Variables & Fields #2

Open bezcan opened 8 years ago

bezcan commented 8 years ago

Quick question, I tried adding fields to the form but have not been able to get the to appear in the sent email.

Here is the code for ajaxContactForm.php

$attachmentsFilesDir = dirname(__FILE__).'/attachments/files';
$resultmsg = array();
$name = "";
$surname = "";
$email = "";
$variable1 = "";
$variable2 = "";
$variable3 = "";
$msg = "";
$attachments = false;

/* ********************************************************************** */
/* Get Input Values */
/* ********************************************************************** */

if($_REQUEST['acf_name']) {
    $name = trim(stripslashes ($_REQUEST['acf_name']));
}

// Surname
if($_REQUEST['acf_name'] && $_REQUEST['acf_surname']) {
    $surname = trim(stripslashes ($_REQUEST['acf_surname']));
    $name = $name." ".$surname;
}

// Variable 1
if($_REQUEST['acf_variable1']) {
    $variable1 = trim(stripslashes ($_REQUEST['acf_variable1']));
}

// Variable 2
if($_REQUEST['acf_variable2']) {
    $variable2 = trim(stripslashes ($_REQUEST['acf_variable2']));
}

// Variable 3
if($_REQUEST['acf_variable3']) {
    $variable3 = trim(stripslashes ($_REQUEST['acf_variable3']));
}

// Email
if($_REQUEST['acf_email']) {
    $email = trim(stripslashes ($_REQUEST['acf_email']));
}

// Mail Subject
if($_REQUEST['acf_subject']) {
    $subject = $subject.trim(stripslashes ($_REQUEST['acf_subject']));
}

// Mail Message
if($_REQUEST['acf_message']) {
    $msg = trim(stripslashes ($_REQUEST['acf_message']));
}

// Attachments
if($_REQUEST['acf_attachments']) {
    $attachments = true;
    $attachmentsFiles = $_REQUEST['acf_attachments'];
    $attachmentsFiles = explode(',', $attachmentsFiles);
}

if ($name == "" || $email == "" || $msg == "") {
    $resultmsg['result'] = "fail";
    $resultmsg['msg'] = "Name, Email and Message fields are required!";
    return $resultmsg;
}

/* ********************************************************************** */
/* MESSAGE BODY SETUP */
/* ********************************************************************** */

$message = "<div style=\"font-family: ".$text_font_family."; font-size:".$text_size."; color:".$text_color.";\">";
if ($messageImage != "") {
    $message .= "<img src=\"".$messageImage."\" alt=\"contact form image\"";
}

$message .= "<h1 style=\"font-size:".$title_size."; color:".$title_color."; margin:10px 0 0 0;\">".$messageTitle."</h1>";
$message .= "<h2 style=\"font-size:".$subtitle_size."; color:".$subtitle_color."; margin:10px 0 0 0;\">".$messageSubTitle."</h2>";
$message .= "<p>From: " .$name. "<br>";
$message .= "E-mail: " .$email. "<br>";
$message .= "Variable 1: " .$variable1. "<br>";
$message .= "Variable 2: " .$variable2. "<br>";
$message .= "Variable 3: " .$variable3. "</p>";
$message .= "<div style=\"margin:10px 0 0 0;\">".$msg."</div>";
$message .= "</div>";

Then for the markup I have this acf-demo.php

                        <!-- Field: Variable1 -->
                        <div class="form-group">
                            <label for="acf_variable1">Variable 1</label>
                            <div class="form-input-error-msg alert alert-danger">
                                <span class="glyphicon glyphicon-exclamation-sign"></span> <span class="error-empty">Empty Field</span>
                            </div>
                            <input type="text" class="form-control validate" name="acf_variable1" id="acf_variable1"
                           data-confirm="#acf_variable1" placeholder="Variable 1">
                        </div>

And so on for variables 1,2, and 3.

What am I doing wrong so that I cannot receive these added variables in the email?