简体   繁体   中英

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

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?

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?

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

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

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

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!

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" .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM