- This topic has 4 replies, 1 voice, and was last updated 13 years, 7 months ago by
Support. This post has been viewed 8729 times
-
AuthorPosts
-
March 13, 2013 at 1:00 am #98
Support
KeymasterFirst, 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!
March 13, 2013 at 1:46 pm #99Support
KeymasterHi,
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.
March 13, 2013 at 2:49 pm #100Support
KeymasterOk, 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>
March 13, 2013 at 6:25 pm #101Support
KeymasterOh, 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.
March 14, 2013 at 2:04 pm #102Support
KeymasterThanks!
-
AuthorPosts
This topic is marked as "RESOLVED" and can not rceive new replies.