dongsheng4679 2015-06-15 19:29
浏览 31
已采纳

无法使用Bootstrap联系表单在WordPress HTML / PHP中工作

I've come across a snippet of bootstrap code that constructs a nice looking contact form that I want to use on a WordPress site. I'm not able to get the form to communicate correctly with the php file given in the form "action".

I'm looking for help as to what my HTML and PHP should look like and how I can get this form to work in WordPress.

here is the HTML:

<form class="form-horizontal" role="form" method="post" action="http://stevetest.dev/wp-content/themes/bones/get_in_touch.php">
 <div class="form-group">
    <label for="Name" class="col-sm-3 control-label"><b>Your name</b></label>
    <div class="col-sm-9">
        <input class="form-control" name="name" id="Name" type="text" placeholder="Your Name or Company">
    </div>
</div>
<div class="form-group">
    <label for="contact-email" class="col-sm-3 control-label"><b>Your Email</b></label>
    <div class="col-sm-9">
        <input class="form-control" id="contact-email" name="contact-email" type="text" placeholder="">
    </div>
</div>
<div class="form-group">
    <label for="contact-message" class="col-sm-3 control-label"><b>Select Topic</b></label>
    <div class="col-sm-9">
        <select class="form-control" id="prependedInput" >
            <option>Please select topic...</option>
            <option>General</option>
            <option>Services</option>
            <option>Orders</option>
        </select>
    </div>
</div>
<div class="form-group">
    <label for="contact-message" class="col-sm-3 control-label"><b>Message</b></label>
    <div class="col-sm-9">
        <textarea class="form-control" rows="5" id="contact-message" name="contact-message"></textarea>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-12">
        <button type="submit" class="btn pull-right">Send</button>
    </div>
</div></form>

Below is the PHP:

<?php
if ($_POST["submit"]) {
    $name = $_POST['Name'];
    $email = $_POST['contact-email'];
    $message = $_POST['contact-message'];
    $from = 'Demo Contact Form'; 
    $to = 'fakeemail@gmail.com'; 
    $subject = 'Message from Contact Demo ';
    $body = "From: $name
 E-Mail: $email
 Message:
 $message";
    // Check if name has been entered
    if (!$_POST['name']) {
        $errName = 'Please enter your name';
    }
    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errEmail = 'Please enter a valid email address';
    }
    //Check if message has been entered
    if (!$_POST['message']) {
        $errMessage = 'Please enter your message';
    }

if (!$errName && !$errEmail && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
    } else {
        $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
    }
}
    }?>

When I submit the form, I get this form. I'm taken to a new page (get_in_touch.php). And I get the following error

Notice: Undefined index: submit in /srv/www/stevetest/htdocs/wp-content/themes/bones/get_in_touch.php on line 2

  • 写回答

2条回答 默认 最新

  • douxiong0668 2015-06-15 19:55
    关注

    there isn't a name field of the input tag (use name attribute in the input tag). Name attribute is important while passing values next pages.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀