bootstrap中的Form不工作.为什么


Form in bootstrap won't work.. Why?

由于某种原因,当我尝试在引导模式中使用我的表单时,它不起作用。我怀疑这与PHP有关,但我不完全确定。

当我点击表单上的提交按钮时,问题发生了。该文档不会激活php, php应该更新mysql,然后将您重定向到另一个页面,而只是刷新当前页面。请记住,这是在模态中。

到目前为止我写的是:

<?php
if(basename($_SERVER["PHP_SELF"]) == "header.php"){
    die("403 - Access Forbidden");
}
    $cookie_name = 'showmodal';
    $cookie_value = 'AlreadySawModal';
    setcookie($cookie_name, $cookie_value, time() + (43200), '/'); // 43200 = 12hr
 ?> 
<?php
if (!isset($_COOKIE[$cookie_name])) {
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link href="<?php echo $siteurl; ?>assets/css/<?php echo $theme;?>.min.css" rel="stylesheet" type="text/css" />
<link href="<?phpecho $siteurl; ?>assets/css/addon.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $siteurl; ?>assets/css/<?php echo $themetype; ?>.css" rel="stylesheet" type="text/css" />

    <div id="myModal" class="modal" role="dialog" aria-hidden="false">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                     <h4 class="modal-title" id="myModalTitle"> You haven't voted in the past 12 hours!? </h4>
                </div>
                <div class="modal-body" id="resize">
    <?php
    $earnedpoints  = false;
    $insertnew     = false;
    $time          = time();
    $redirect      = "";
    $account       = $mysqli->real_escape_string(preg_replace("/[^A-Za-z0-9 ]/", '', @$_POST['name']));
    $siteid        = $mysqli->real_escape_string(@$_POST['votingsite']);
    $checkacc      = $mysqli->query("SELECT * FROM accounts WHERE name = '$account'");
    $countcheckacc = $checkacc->num_rows;
    if ($countcheckacc == 0 && isset($_POST['submit'])) {
        $funct_error = "This account doesn't exist!";
    } elseif ($account == '' && isset($_POST['submit'])) {
        $funct_error = 'You need to put in a username!';
    } elseif (empty($_POST['votingsite']) && isset($_POST['submit'])) {
        $funct_error = "Please select a voting site";
    } elseif (isset($_POST['submit'])) {
        $result = $mysqli->query("SELECT *, SUM(times) as amount FROM " . $prefix . "votingrecords WHERE NOT account='' AND NOT account='0' AND account='" . $account . "' AND siteid = '" . $siteid . "'") or die('Error - Could not look up vote record!');
        $row       = $result->fetch_assoc();
        $sitequery = $mysqli->query("SELECT * FROM " . $prefix . "vote WHERE id = '" . $siteid . "'");
        $vsite     = $sitequery->fetch_assoc();
        $gvp       = $vsite['gvp'];
        $gnx       = $vsite['gnx'];
        $timecalc  = $time - $row['date'];
        if ($row['amount'] == '' || $timecalc > $vsite['waittime']) {
            if ($row['amount'] == '') {
                $result = $mysqli->query("INSERT INTO " . $prefix . "votingrecords (siteid, ip, account, date, times) VALUES ('" . $siteid . "', '" . $ipaddress . "', '" . $account . "', '" . $time . "', '1')") or die('Error - Could not insert vote records!');
            } else {
                $result = $mysqli->query("UPDATE " . $prefix . "votingrecords SET siteid = '" . $siteid . "', ip='" . $ipaddress . "', account='" . $account . "', date='" . $time . "', times='1' WHERE account='" . $account . "' AND siteid = '" . $siteid . "'") or die('Error - Could not update vote records!');
            }
            $earnedpoints = true;
            if ($earnedpoints == true) {
                if ($account != '') {
                    $result = $mysqli->query("UPDATE accounts SET $colvp = $colvp + $gvp, $colnx = $colnx + $gnx WHERE name='" . $account . "'") or die('Error - Could not update account!');
                }
                $funct_msg = '<meta http-equiv="refresh" content="0"; url=' . $vsite['link'] . '">';
                $redirect  = true;
            }
        } elseif ($timecalc < $vsite['waittime'] && $row['amount'] != '') {
            $funct_msg = 'You''ve already voted for ' . $vsite['name'] . ' within the last ' . round($vsite['waittime'] / 3600) . ' hours!';
            $funct_msg .= '<br />Vote time: ' . date('M d', h:i A', $row['date']);
        } else {
            $funct_error = 'Unknown Error';
        }
    }
    if ($redirect == true) {
        echo $funct_msg;
    }
    else {
?> 
<form method="post">  
    <?php
        if (isset($funct_msg)) {
            echo '<div class="alert alert-danger">' . $funct_msg . '</div>';
        }
        if (isset($funct_error)) {
            echo '<div class="alert alert-danger">' . $funct_error . '</div>';
        }
        $query = $mysqli->query("SELECT * from " . $prefix . "vote");
        if ($query->num_rows == 0) {
            echo "<div class='"alert alert-danger'">Your administrator has not added any voting sites yet!</div>";
        }
        echo "
        <div class='"form-group'">
        <label for='"voteSite'">Select Site:</label>
        <select name='"votingsite'" class='"form-control'" id='"voteSite'" required>
        <option value='"'" disabled selected>Select Site...</option>";
        while ($row = $query->fetch_assoc()) {
            echo "<option value='"" . $row['id'] . "'">" . $row['name'] . "</option>";
        }
        echo "</select>
        </div>";
        if (!isset($_SESSION['id'])) {
            echo "<input type='"text'" name='"name'" maxlength='"15'" class='"form-control'" placeholder='"Username'" required autocomplete='"off'"/><br/>";
        } else {
            echo "<input type='"text'" name='"name'" maxlength='"15'" class='"form-control'" placeholder='"" . $_SESSION['name'] . "'" value='"" . $_SESSION['name'] . "'"required autocomplete='"off'"/><br/>";
        }
?>
    <button type="submit" name="submit" class="btn btn-primary">Vote &raquo;</button>
</form> 
<br/>
                </div>
            </div>
        </div>
    </div>
    <script> $('#myModal').modal('show'); </script>
    <?php
    }
?>
<?php
} else {
?>
<link href="<?php echo $siteurl; ?>assets/css/<?php echo $theme; ?>.min.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $siteurl; ?>assets/css/addon.css" rel="stylesheet" type="text/css" />
<link href="<?php echo $siteurl; ?>assets/css/<?php echo $themetype;?>.css" rel="stylesheet" type="text/css" />
<?php
}
?>

模态工作得很好,它只是表单没有提交/执行php代码。

任何和所有的帮助感谢!

编辑:有人告诉我,虽然不是W3C有效的,但如果您想让脚本自己启动,则不需要操作标记。也只是从(根据http://www.w3schools.com/tags/att_form_action.asp表单标签是不需要在HTML5:O),所以

<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post"> 

相同
<form method="post">

可能的解决方案:

1)"表单"标签中没有指定动作?

也许你应该改变
<button type="submit">

<input type="submit" name="submit" value="Submit form">

3)尝试添加这段代码,看看是否真的没有post数据,因为$_POST['submit']没有指定…

if ($_SERVER['REQUEST_METHOD']=='POST') {
    echo "there's a post submitted";
}
4)尝试清理你的PHP代码,使用正确的OO原则/模式来管理表单和数据。