Hello,
I have added an extra field to the form but its not working correctly. I have updated both template_contact.php and send.php. Basically all fields by default are required (red box highlights around field when you select send without filling in any details). Issue: When I select send without filling any details only 3 (original fields) out of the 4 fields are highlighted. If I fill only the highlighted fields and select send the contact form disappears and no mail is received. If I fill in all 4 fields and select send the thank you message appears and mail is received. Somehow I need to activate the 4th required field.
I have pasted both the updated template_contact.php and send.php files below. The new field is titled 'company' / 'the_company'.
template_contact.php
<?php
/*
Template Name: Contact Form
*/
global $k_options;
$name_of_your_site = get_option('blogname');
$email_adress_reciever = $k_options['contact']['contact_mail'] != "" ? $k_options['contact']['contact_mail'] : get_option('admin_email');
if(isset($_POST['Send']))
{
include('send.php');
}
get_header(); ?>
<div id="content" class="bg_sidebar">
<div id="inner_content">
<?php if (have_posts()) : while (have_posts()) : the_post();
$punchline = get_post_meta($post->ID, "punchline", true);
$portfolio_image = get_post_meta($post->ID, "portfolio-image", true);
?>
<div class="entry">
<span class="meta"><?php echo $punchline; ?></span>
<h2><a>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-content">
<?php
if($portfolio_image != "") echo '<img src="'.$portfolio_image.'" alt="" />';
?>
<?php the_content(); ?>
</div><!--end entry-content-->
<form action="" method="post" class="ajax_form">
<fieldset><?php if (!isset($errorC) || $errorC == true){ ?><!--<legend><span>Contact Us</span></legend>-->
<p class="<?php echo $the_companyclass; ?>" ><input name="company" class="text_input empty" type="text" id="company" size="20" value='<?php echo $the_company?>'><label for="company">Company Name*</label>
</p>
<p class="<?php echo $the_nameclass; ?>" ><input name="yourname" class="text_input empty" type="text" id="name" size="20" value='<?php echo $the_name?>'><label for="name">Full Name*</label>
</p>
<p class="<?php echo $the_emailclass; ?>" ><input name="email" class="text_input email" type="text" id="email" size="20" value='<?php echo $the_email?>'><label for="email">E-Mail*</label></p>
<!--<p><input name="website" class="text_input" type="text" id="website" size="20" value="<?php echo $the_website?>"/><label for="website">Website</label></p>-->
<label for="message" class="blocklabel">Your Message*</label>
<p class="<?php echo $the_messageclass; ?>"><textarea name="message" class="text_area empty" cols="40" rows="7" id="message"><?php echo $the_message ?></textarea></p>
<p>
<input type="hidden" id="myemail" name="myemail" value="<?php echo $email_adress_reciever; ?>">
<input type="hidden" id="myblogname" name="myblogname" value="<?php echo $name_of_your_site; ?>">
<input name="Send" type="submit" value="Send" class="button" id="send" size="16"></p>
<?php } else { ?>
<p><h3>Your message has been sent!</h3> Thank you!</p>
<?php } ?>
</fieldset>
</form>
</div><!--end entry-->
</div><!-- end inner_content-->
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<!--do not delete-->
<?php endif; ?>
<?php get_sidebar(); ?>
</div><!-- end content-->
<?php get_footer(); ?>
send.php
<?php
if(isset($_POST['Send'])){
$errorC = false;
$the_company = $_POST['company'];
$the_name = $_POST['yourname'];
$the_email = $_POST['email'];
$the_message = $_POST['message'];
#want to add aditional fields? first add them to the form in template_contact.php, then create variables like the ones above
#
# $your_field = $_POST['name_of_your_field'];
#
# last thing to do is to edit the message, see bottom of this file
if(!checkmymail($the_email))
{
$errorC = true;
$the_emailclass = "error";
}else{
$the_emailclass = "valid";
}
if($the_company == "")
{
$errorC = true;
$the_companyclass = "error";
}else{
$the_companyclass = "valid";
}
if($the_name == "")
{
$errorC = true;
$the_nameclass = "error";
}else{
$the_nameclass = "valid";
}
if($the_message == "")
{
$errorC = true;
$the_messageclass = "error";
}else{
$the_messageclass = "valid";
}
if($errorC == false)
{
$to = $_POST['myemail'];
$subject = "New Message from " . $_POST['myblogname'];
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$header .= 'From:'. $_POST['email'] . " \r\n";
$message1 = nl2br($_POST['message']);
$message = "New message from $the_company
Name: $the_name
Mail: $the_email
Message: $message1 ";
/*
$message = "New message from $the_name
YOUR FIELD: $your_field
Mail: $the_email
Message: $message1 ";
*/
mail($to,
$subject,
$message,
$header);
if(isset($_POST['ajax'])){
echo"<h3>Your message has been sent!</h3><p> Thank you!</p>";
}
}
}
function checkmymail($mailadresse){
$email_flag=preg_match("!^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$!",$mailadresse);
return $email_flag;
}
?>
Thank you
Jason














