簡體   English   中英

無法獲取Bootstrap聯系人表單以在WordPress HTML / PHP中工作

[英]Not able to get a Bootstrap contact form to work in WordPress HTML/PHP

我遇到了一段引導代碼,這些引導代碼構造了一個我希望在WordPress網站上使用的漂亮的聯系表單。 我無法獲得與表單“操作”中指定的php文件正確通信的表單。

我正在尋找有關HTML和PHP外觀以及如何使此表單在WordPress中工作的幫助。

這是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>

下面是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\n E-Mail: $email\n Message:\n $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>';
    }
}
    }?>

當我提交表格時,我得到了這張表格。 我被帶到一個新頁面(get_in_touch.php)。 我得到以下錯誤

注意:未定義的索引:在第2行的/srv/www/stevetest/htdocs/wp-content/themes/bones/get_in_touch.php中提交

輸入標簽沒有名稱字段(在輸入標簽中使用name屬性)。 在下一頁傳遞值時,名稱屬性很重要。

我建議您使用聯系表7 https://wordpress.org/plugins/contact-form-7/或類似的插件,並添加自己的HTML類,就像您希望它看起來一樣。

您的代碼現在存在安全性問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM