I'm processing a form using PHP
and JQuery
and it's not processing the way it should normally process. My HTML
is:
<form action="" method="POST" name="forgot_pass_form">
<label><h3>Please Enter your email!</h3></label><br>
<input type="text" name="email_pass" id="email_pass" />
<input type="submit" name="submit" id="submit" value="Submit" />
</form>
My JQuery
code which is in the same page as HTML
code:
<script type="text/javascript">
$(document).ready(function($) {
var email = $('#email_pass').val();
$("#submit").live('click', function(){
$.post('email_password.php',
{
'email_pass' : email
},
function(data) {
alert(data);
});
return false;
});
});
</script>
My PHP
code which is on email_password.php
:
<?php
$email = $_POST['email_pass'];
if(empty($email)){
echo 'empty';
} else {
echo 'Not';
}
?>
The problem here is it always alert me with empty
even if I've entered something in the text box
I even tried this way:
if(empty($_POST)){
echo 'empty';
} else {
// process the form
$email = $_POST['email'];
if(empty($email)){
echo 'Email is empty';
} else {
echo 'Email is not empty';
}
}
By trying this way, it alerts me with Email is empty
. Please help