I have a login form and script on index.php
. The problem is that the PHP code doesn't seem to pick up the fields I put in.
Here is the PHP code:
<?php
if(isset($_POST['user'])||isset($_POST['pass'])){
?>
<script>
$('#login-drop').addClass('open');
console.log('Opening');
</script>
<?php
if(isset($_POST['user'])){
if(isset($_POST['pass'])){
login();
} else{
?>
<script>
$('#pass-group').addClass('has-error');
console.log('Password has error.');
</script>
<?php
}
} else {
?>
<script>
$('#user-group').addClass('has-error');
console.log('User has error');
</script>
<?php
}
} else {
echo 'Nothing was entered';
}
function login(){
echo 'Both username and password was entered.';
}
?>
Here is my HTML form:
<form class="form-horizontal" method="post" action="?login">
<fieldset>
<legend>Log in</legend>
<div class="form-group" id="user-group">
<label for="user" class="col-lg-2 control-label">Username</label>
<div class="col-lg-10">
<input class="form-control" id="user" placeholder="Username or Email" type="text">
</div>
</div>
<div class="form-group" id="pass-group">
<label for="pass" class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input class="form-control" id="pass" placeholder="Password" type="password">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-primary" type="submit">Log in</button>
</div>
</div>
</fieldset>
</form>
Even if I enter the fields it still says Nothing was entered.
I can't see the problem but I tend to overlook things a lot.
PS. I'm using Bootstrap so the classes should work. I've tested them.