表单提交不适用于 twitter bootstrap (PHP $_POST)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8444257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:43:43  来源:igfitidea点击:

Form submit not working with twitter bootstrap (PHP $_POST)

phpbuttonsubmittwitter-bootstrap

提问by BLACKBERRY COCONUT

I just started using twitter bootstrap, and I got stuck trying to get my form submit button to submit (PHP $_POST). Does anyone know why its not working?

我刚开始使用 twitter bootstrap,我在尝试让我的表单提交按钮提交(PHP $_POST)时遇到了困难。有谁知道为什么它不起作用?

No clue really..

真的没有头绪。。

I've been doing this previously and its been working until bootstrap:

我以前一直在这样做,它一直在工作,直到引导:

<?php
if (isset($_POST["login"]) && $_POST["login"]=="login") {
echo "login here";
}
?>

<form action="http://mysite.com" method="post">
<input type="hidden" id="login" name="login" value="login" />
<button class="btn success" type="submit">Login</button>
</form>

The page seems to load but the PHP does not. Is the POST information being blocked?

该页面似乎加载,但 PHP 没有。POST 信息是否被阻止?

回答by BLACKBERRY COCONUT

My form input elements did not have an id or name (I didn't include them in my example).

我的表单输入元素没有 id 或名称(我的示例中没有包含它们)

回答by olex

Not an HTML expert, but I've always used <input type="submit" />and not <button type="submit" />, not sure that buttonis a functional form element.

不是 HTML 专家,但我一直使用<input type="submit" />and not <button type="submit" />,不确定这button是一个功能表单元素。

Also, your buttonelement is closed twice - first with />in the opening tag, and then again with a closing tag for no reason.

此外,您的button元素被关闭两次 - 首先是/>在开始标签中,然后是无缘无故的结束标签。

回答by lorenzo-s

Maybe you are wrong with the action="http://mysite.com"? That attribute is for specifing the form data receiver, so in your case I think it's the page itself. So, if your page is named mypage.php, use action="mypage.php".

也许你错了action="http://mysite.com"?该属性用于指定表单数据接收器,因此在您的情况下,我认为它是页面本身。因此,如果您的页面名为mypage.php,请使用action="mypage.php".

回答by hambone

I had this same issue as well, turns out I was missing the name="submit". Gotta have that so the $_POST has a key in the assoc array!

我也有同样的问题,结果我错过了 name="submit"。必须拥有它,所以 $_POST 在 assoc 数组中有一个键!

回答by Victor Okun

it is adviseable that every element has a name thus (name="elementName") this makes it easy to reference them in your php scipt; also ensure that a form action and method are set.

建议每个元素都有一个名称,因此 (name="elementName") 这样可以很容易地在您的 php scipt 中引用它们;还要确保设置了表单操作和方法。