联系表单问题(bootstrap 3和php)

时间:2014-11-03 18:25:31

标签: php html forms twitter-bootstrap

我是新手,虽然它帮助我在过去找到答案,但我很抱歉打扰另一个简单的问题。

我用BS3设计了一个简单的联系表格。 (请将窗口调整为小视口大小,以便显示相关的“联系我们”模式!)www.centurius.de/_LETSGO/index.html

模态HTML

<div class="row visible-sm">
  <a data-toggle="modal" href="#myModal" class="btn btn-medium btn-block btn-default"><span class="glyphicon glyphicon-envelope"></span>&nbsp;&nbsp;Contact us!</a>
  <div class="modal fade" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
          <h4 class="modal-title">Send us an inquiry!</h4>
        </div>
        <div class="modal-body">
          <form role="form" method="post" action="contact.php">
          <div class="form-group">
            <label>Your Name</label>
            <div class="input-group">
            <input name="InputName" id="InputName" class="form-control" placeholder="Enter Name" required></input>
            <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span></div>
          </div>
          <div class="form-group">
            <label for="InputEmail">Your Email</label>
            <div class="input-group">
              <input type="email" class="form-control" id="InputEmail" name="InputEmail" placeholder="Enter Email" required>
              <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
            </div>
          </div>
          <div class="form-group">
            <label for="InputMessage">Message</label>
            <div class="input-group">
              <textarea name="InputMessage" id="InputMessage" class="form-control" placeholder="Enter Message" rows="5" required></textarea>
              <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
            </div>
          </div>
          <div class="form-group">
            <label>Anti-Spam</label>
            <div class="input-group">
              <input name="InputHuman" id="InputHuman" class="form-control" placeholder="What's 2+2?" required></input>
              <span class="input-group-addon"><i class="glyphicon glyphicon-ok form-control-feedback"></i></span>
            </div>
          </div>
          <hr class="featurette-divider hidden-lg">
          <div class="container">
            <h4>Centurius Import Export GmbH</h4>
             <p>Poppenb&uuml;tteler Bogen 66<br>
             22399 Hamburg<br>
             Germany<br>
             <a href="mailto:info@centurius.de?Subject=Website%20inquiry" target="_top">info@centurius.de</a></p>
           </div>
          </form>
        </div>
        <div class="modal-footer">
          <input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">
        </div>
      </div>
    </div>
  </div>
</div>

相应的PHP代码如下所示:

    <?php        
    /* Set e-mail recipient */
    $name = $_POST['InputName'];
    $email = $_POST['InputEmail'];
    $message = $_POST['InputMessage'];
    $from = 'BryanDemo';
    $to = 'info@centurius.de';
    $subject = 'Website inquiry'
    $human = $_POST['InputHuman'];
    $body = "From: $name\n E-Mail: $email\n Message: $message\n";
    if ($_POST['submit'] && $human == '4') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        }
    } else if ($_POST['submit'] && $human != '4') {
        echo '<p>Change anti-spam answer to "4"</p>';
    }
    ?>

服务器设置为支持php。

关于如何让这个宝宝跑步的任何想法?

是的,我曾尝试与社区互动,但在浏览问题后我无法回答一个问题:(

非常感谢!

1 个答案:

答案 0 :(得分:0)

您的提交代码<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">位于<form>代码之外。

<form role="form" method="post" action="contact.php">
<input type="text" id="example">
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-info pull-right">
</form>

此外,您需要在PHP文件中$subject = 'Website inquiry'之后使用分号。