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

5

5

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?

Miamiami answered 9/12, 2011 at 10:37 Comment(4)
We can't help you without some piece of code! ...And, bootstrap what? The one from Twitter?Dusk
This really has nothing to do with Bootstrap. Bootstrap is a HTML/CSS/JS framework, nothing server-side.Esculent
Do $_GET variables pass? Try using action="get". And try to remove Twitter Bootstrap now to see if it comes back to life.Dusk
I have the exact same problem. I'm using the twitter bootstrap framework for my site, and spent way too long banging my head against this issue. Still don't have a solution, but for some reason if I have the form input set to use the button tag instead of input tags, $_POST is always empty. So wierd.Pusillanimity
M
8

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

Miamiami answered 10/12, 2011 at 0:23 Comment(0)
F
3

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.

Fancy answered 9/12, 2011 at 11:29 Comment(1)
I truly believe its not an HTML problem. Like i noted, this code has worked for me previous to bootstrap. And the page does seem to load, however the $_POST information seems to be blocked so therefore my login code is not being triggered.Miamiami
D
0

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

Dusk answered 9/12, 2011 at 11:32 Comment(1)
I double checked, this does not change anything. The page loads, the problem seems to be with the $_POST information not being passed. This seems like a very unusual problem, I'm surprised no one has encountered this before..Miamiami
S
0

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!

Sensationalism answered 1/12, 2014 at 22:49 Comment(0)
I
-2

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.

Inferential answered 13/2, 2017 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.