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 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机