doushi3803 2013-03-02 21:58
浏览 91
已采纳

Wordpress联系表格

I've a very basic contact form on my Wordpress site (hard coded) and I can't get things to work. It works locally fine through XAMPP and I'm sure it's something I'm just missing but any help would be greatly appreciated. Thanks in advance!. I'm also using a template I created

<?php /* Template Name: contact */?>

<?php get_header(); ?>

<?php

//vars declared to store form input
$name=$email=$comment=$phone="";
//Error vars - to relay error message to the form 
$nameError=$emailError=$commentError="";
$error_message="";
$sentMessage="";
$status=0; //Will monitor if all fields have no errors and increment if so.

function sanitise_var($string){
    htmlentities($string);
    strip_tags($string);
    return stripslashes($string);
}

if(isset($_POST['submitted'])){

if($_POST['name']==""){ 
    $nameError="Please enter a name";
    $error_message="Oops, error in the form. Please check";

}

else {
    $name=$_POST['name'];
    ++$status;

}

if($_POST['email'] == "" || !preg_match("/^[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", $_POST['email'])){ 
    $error_message="Oops, error in the form. Please check";
    $emailError="Please enter a valid email";

}

else{
    $email=$_POST['email'];
    ++$status;
}

if(!$_POST['phone']=="") $phone=$_POST['phone'];

if($_POST['comment']==""){ 
    $error_message="Oops, error in the form. Please check";
    $commentError="Please enter a message";
}

else{
    $comment=$_POST['comment'];  
    ++$status;

 }


}//submitted if statement


if($status==3 && $_POST['submitted']){ 
    $sentMessage="From: $name, email: $email, Phone: $phone, Comment: $comment";
    wp_mail("mathornley@gmail.com", "From Android Scoop contact form", $sentMessage);
    echo "Thanks, your email was sent successfully!";
}

else{

echo<<<SOQ

<div class="entry-content">         

    <h1 class="entry-title">Contact</h1>

        <p class="contact">
            If you have a query drop us a line using the form below. We're always  happy to hear from people with ideas for posts and content they'd like to           feature or maybe write about. Or maybe you just have some feedback you'd like to share with us. Why not just swing by and say hello. 
        </p>       
        <p class="requiring">* Denotes required fields</p>       

        <div class="form_left">     

    <form action="/contact/" method="POST">
                <p><label>Name:</label><input type="text" name="name" value="$name"/></p> 
                <p class="error">$nameError</p> 
                <p><label>Email</label><input type="text" name="email" value="$email"/></p>
                <p class="error">$emailError</p> 
                <p><label>Phone:</label><input type="text" name="phone" value="$phone"/></p> 
                <input type="hidden" name="submitted" value="yes"/>
                <input type="submit" value="Send your message"/>                        
        </div>

        <div class="form_right">        
                <p><label>Message:</label><br/><textarea name="comment" rows="20" cols="20">$comment</textarea></p>
                <p class="error">$commentError</p> 
            </form>
        </div>
</div>

SOQ;

}
?> 

<?php get_footer();?>
  • 写回答

3条回答 默认 最新

  • dongren1986 2013-03-02 22:50
    关注

    Try to use blank value for action like:

    <form action="" method="POST">
    

    If that doesn't work try renaming name parameter of the first input field to something else like:

    <input type="text" name="myname" value="$name"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么