doumen5491 2014-12-18 21:05
浏览 64
已采纳

使用Bootstrap输入按钮不起作用

I have been using Bootstrap 3 to develop a project im working on and so far it has worked wonders and cant really fault it. However I have now run into a problem that I cant seem to get my head around.

Problem: A basic input submit button not doing anything - but when run on its own page i.e. without bootstrap it runs fine.

Here is the code:

<section>
    <div class="container">
        <div class="col-md-6">

            <?php
                // define variables and set to empty values
                $name = $email = $gender = $comment = $website = "";

                if ($_SERVER["REQUEST_METHOD"] == "POST") {
                   $name = test_input($_POST["name"]);
                   $email = test_input($_POST["email"]);
                   $message = test_input($_POST["message"]);
                }

                function test_input($data) {
                   $data = trim($data);
                   $data = stripslashes($data);
                   $data = htmlspecialchars($data);
                   return $data;
                }
                ?>

                <h2>PHP Form Validation Example</h2>
                <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                   Name: <input type="text" name="name">
                   <br><br>
                   E-mail: <input type="text" name="email">
                   <br><br>
                   Comment: <br>
                    <textarea name="message" rows="5" cols="40"></textarea>
                   <br><br>
                   <input type="submit" name="submit" value="Submit">
                </form>

                <?php
                echo "<h2>Your Input:</h2>";
                echo $name;
                echo "<br>";
                echo $email;
                echo "<br>";
                echo $comment;
            ?>

        </div>
    </div>
</section>

If you need to have a look at it running on a page with other content you can do so here

Also I am planning to get this working as a contact form, but no matter what PHP code I put I still get this problem.

  • 写回答

2条回答 默认 最新

  • dtg78700 2014-12-18 21:22
    关注

    You have this code in your contact_me.js that's causing the issue:

    8.   submitSuccess: function($form, event) {
    9.     event.preventDefault(); // prevent default submit behaviour
    10.    // get values from FORM
    11.    var name = $("input#name").val();
    ...
    15.    var firstName = name; // For Success/Failure Message
    16.    // Check for white space in name for Success/Fail message
    17.    if (firstName.indexOf(' ') >= 0) {
    18.      firstName = name.split(' ').slice(0, -1).join(' ');
    ...
    

    Console returns the error:

    TypeError: firstName is undefined
    

    I think you're selecting the name improperly. Try using:

    var name = $("input[name=name]").val();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决