向contact.php添加新字段

时间:2015-06-17 22:36:38

标签: php wordpress

几个月前我买了一个WP主题,效果很好!我正在尝试编辑contact.php / sendmail.php

我已成功添加到字段中,它显示在电子邮件正文中并正确发送。但是,当字段尚未填写时,我很难将新字段“感兴趣的学校”正确地突出显示(隐藏文本)。有问题的联系表格可以在这里找到:http://www.northbrookmontessori.org/school-tours/

sendmail.php

<?php
    //validate fields
$errors = '';

//has the form's submit button been pressed?
if( !empty( $_POST['myformsubmit'] ) )
{
    // HAS THE SPAM TRAP FIELD BEEN FILLED IN?
    if( !empty( $_POST['favouriteColour'] ) )
    {
        exit;
    }

$myemail = $_POST['youremail'];
$thankyou = $_POST['thankyou'];
$formerror = $_POST['formerror'];
if(empty($_POST['name'])  || 
   empty($_POST['school']) ||
   empty($_POST['email']) ||
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$school = $_POST['school']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } //send email

if( empty($errors))
{
   $to = $myemail; 
   $email_subject = "Contact form submission from $name";
   $email_body = "$name has sent you this email through the contact form: \n \n".
   "Name: $name \n".
   "School(s) of interest: $school \n".
   "Email: $email_address \nMessage: \n\n$message";

   $headers = "From: $email_address"; 

   mail($to,$email_subject,$email_body,$headers);
   //redirect to the 'thank you' page
   header('Location: ' . $thankyou);
}
else {
   header('Location: ' . $formerror);
   }

}

?>

contact.php

<!-- ***** CONTACT -->
<div class="block_wrapper <?php if($bb_animation == 'yes'){ echo 'animation' . $anim1_number; ?> animated <?php } ?><?php echo ' '.$custom_width; ?>">

    <div class="box_full<?php if($margin_top != ''){echo ' ' . $margin_top;} ?><?php if($margin_bottom != ''){echo ' ' . $margin_bottom;} ?><?php if($custom_classes != NULL){echo ' ' . $custom_classes;} ?>">

    <form id="theform" class="form mt35" method="post" action="<?php echo get_template_directory_uri(); ?>/sendmail.php">

    <p class="hRow">
        <label for="favouriteColour">Favourite colour (do not fill in)</label>
        <span><input type="text" name="favouriteColour" id="favouriteColour" value="" /></span>
    </p>

    <input type="hidden" name="youremail" id="youremail" value="<?php if(!empty($contact_email)){echo $contact_email;} ?>" />

    <input type="hidden" name="thankyou" id="thankyou" value="<?php if(!empty($contact_thankyou)){echo $contact_thankyou;} ?>" />

    <input type="hidden" name="formerror" id="formerror" value="<?php if(!empty($contact_error)){echo $contact_error;} ?>" />

    <p class="name validated">
        <label for="name">Name</label>
        <span><input type="text" name="name" id="name" /></span>
    </p>

    <p class="school validated">
        <label for="school">School(s) of interest</label>
        <span><input type="text" name="school" id="school" /></span>
    </p>

    <p class="email validated">
        <label for="email">E-mail</label>
        <span><input type="text" name="email" id="email" /></span>
    </p>

    <p class="text validated">
        <label for="message">Message</label>
        <textarea name="message" id="message" rows="50" cols="100"></textarea>
    </p>

    <p class="submit">
        <input type="submit" class="buttonmedium float_r" name="myformsubmit" value="Send Email" />
    </p>
    <p id="error">* There were errors on the form, please re-check the fields.</p>
    </form>

    </div>

    <div class="clear"></div>

</div><!-- ***** END CONTACT -->

1 个答案:

答案 0 :(得分:1)

你需要转到文件:

http://www.northbrookmontessori.org/wp-content/themes/modular/js/settings.js?ver=4.2.2

并编辑顶部的位置:

  

//在此处放置所有必填字段的ID。

添加学校