douren4075 2015-06-17 22:36
浏览 32

向contact.php添加新字段

I bought a WP theme a few months ago and it works great! I am trying to edit the contact.php / sendmail.php

I have successfully added in a field, it shows up in the body of the email and sends correctly. However, I am have a lot of trouble getting the new field "school(s) of interest" to highlight properly (with hidden text) when the field hasn't been filled. The contact form in question can be found here: 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 .= "
 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 .= "
 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: 
 
".
   "Name: $name 
".
   "School(s) of interest: $school 
".
   "Email: $email_address 
Message: 

$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条回答 默认 最新

  • drwdvftp423507 2015-06-17 22:53
    关注

    you need to go to the file:

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

    and edit the top where it says:

    // Place ID's of all required fields here.

    add in school

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测