Contact Form Additions

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #98
    Support
    Keymaster

    First, thank you for your help with the contact form drop-down! Worked perfectly.  How can I add a new entry such as phone and make it not required?  Also, how can I make subject not required?
     
     
    Thanks again!


    #99
    Support
    Keymaster

    Hi,

    First thing you gotta do is to go to the file js/views/view.contact.js and remove that line:

    
    subject: {
    	required: true
    },
    

    It will make the subject not required anymore.

    For new fields, you just need to add it in the html and then add the reference to the PHP send the email:

    Open php/contact-form.php

    And do something like this:

    
    $fields = array(
    	0 => array(
    		'text' => 'Name',
    		'val' => $_POST['name']
    	),
    	1 => array(
    		'text' => 'Email address',
    		'val' => $_POST['email']
    	),
    	2 => array(
    		'text' => 'Message',
    		'val' => $_POST['message']
    	),
    	3 => array(
    		'text' => 'Field Name',
    		'val' => $_POST['fieldID']
    	)
    );
    

    Replace the Field Name and fieldId to match what you put in the HTML file.


    #100
    Support
    Keymaster

    Ok, got it but for some reason the field name carries over to the email I receive but not the field content.  Any ideas why this might be?  Thanks!
     
    Name: Ryan
    Email address: [email protected]
    Message: test
    Phone:

    <?php
    session_cache_limiter(‘nocache’);
    header(‘Expires: ‘ . gmdate(‘r’, 0));

    header(‘Content-type: application/json’);

    // Your email address
    $to = ‘[email protected]’;

    $subject = $_POST[‘subject’];;

    if($to) {
    $name = $_POST[‘name’];
    $email = $_POST[’email’];

    $fields = array(
    0 => array(
    ‘text’ => ‘Name’,
    ‘val’ => $_POST[‘name’]
    ),
    1 => array(
    ‘text’ => ‘Email address’,
    ‘val’ => $_POST[’email’]
    ),
    2 => array(
    ‘text’ => ‘Message’,
    ‘val’ => $_POST[‘message’]
    ),
    3 => array(
    ‘text’ => ‘Phone’,
    ‘val’ => $_POST[‘phone’]
    )
    );

    $message = “”;

    foreach($fields as $field) {
    $message .= $field[‘text’].”: ” . htmlspecialchars($field[‘val’], ENT_QUOTES) . “<br>\n”;
    }

    $headers = “MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\n”;
    $headers .= “From: \”” . $name . “\” \r\n”;
    $headers .= “Reply-To: ” .  $email . “\r\n”;
    $message = utf8_decode($message);

    mail($to, $subject, $message, $headers);

    if ($message){
    $arrResult = array (‘response’=>’success’);
    } else{
    $arrResult = array (‘response’=>’error’);
    }

    echo json_encode($arrResult);

    } else {

    $arrResult = array (‘response’=>’error’);
    echo json_encode($arrResult);

    }
    ?>

    <form action=”” id=”contactForm” type=”post”>
    <div class=”row controls”>
    <div class=”span3 control-group”>
    <label>Your name *</label>
    <input type=”text” value=”” maxlength=”100″ class=”span3″ name=”name” id=”name”>
    </div>
    <div class=”span3 control-group”>
    <label>Your email address *</label>
    <input type=”email” value=”” maxlength=”100″ class=”span3″ name=”email” id=”email”>
    </div>
    </div>
    <div class=”row controls”>
    <div class=”span3 control-group”>
    <label>Your Phone</label>
    <input type=”text” value=”” maxlength=”100″ class=”span3″ name=”phone” id=”phone”>
    </div>
    </div>
    <div class=”row controls”>
    <div class=”span3 control-group”>
    <label>Subject</label>
    <select class=”span3″ name=”subject” id=”subject”>
        <option value=”-Select one-“>-SELECT ONE-</option>
        <option value=”Social Media Quote”>I’d like Social Media Quote</option>
        <option value=”Please contact me”>Please contact me</option>
    <option value=”I have a question”>I have a question</option>
        <option value=”Other”>Other</option>

    </select>
    </div>
    </div>
    <div class=”row controls”>
    <div class=”span6 control-group”>
    <label>Message *</label>
    <textarea maxlength=”5000″ rows=”10″ class=”span6″ name=”message” id=”message”></textarea>
    </div>
    </div>
    <div class=”alert alert-success hidden” id=”contactSuccess”>
    <strong>SUCCESS!</strong> Your message has been sent to us and someone will be in touch with you shortly.
    </div>
    <div class=”alert alert-error hidden” id=”contactError”>
    <strong>Oh snap!</strong> There was an error sending your message.
    </div>
    <div class=”btn-toolbar”>
    <input type=”submit” value=”Send Message” class=”btn btn-primary btn-large” data-loading-text=”Loading…”>
    </div>
    </form>
     


    #101
    Support
    Keymaster

    Oh, I’m sorry, I forgot one thing 🙂

    Again in the file view.contact.js add this line:

    
    "phone": $("#contactForm #phone").val(),
    

    After the line 45.


    #102
    Support
    Keymaster

    Thanks!


Viewing 5 posts - 1 through 5 (of 5 total)

This topic is marked as "RESOLVED" and can not rceive new replies.