Hello guys.
My problem is that even though I have return false on the submit function, page still reloads while input type="submit". When I change input type to button, form does not get submitted even though I reference $('#former').submit
Appreciate your help and thank you in advance.
jscript code
$(document).ready(function(){
$('#former').submit(function() {
$.ajax({
type: "POST",
url: 'post.php',
data: $('#e').attr('value').serialize(),
dataType: "text/html",
cache: false,
success: function(html){
$("#green").html(html);
}
});
return false;
});
});
HTML combined with PHP lives on the same page as jscript above.
<?php
require_once('post.php');
testME();
?>
<form id="former" action="" method="POST">
<?php
if(isset($_SESSION['offers']) && $_SESSION['offers'] == '1'){
print '<div class="sub" title="unsabscribe"> <input type="hidden" id="e" name="email" value="unsub" /><input type="button" value="Unsubscribe" /></div>';
} else {
print '<div class="sub" title="unsabscribe"><input type="hidden" id="e" name="email" value="sub" /><input type="button" value="Subscribe" /></div>';
}
//var_dump($_SESSION);
//var_dump($_POST);
?>
</form>
PHP function lives in post.php
<?php
session_start();
//unsubscribe
function testME(){
if(isset($_POST['email']) && $_POST['email'] == 'unsub'){
$_SESSION['offers'] = '0';
print 'this is 0';
} else
//unsubscribe for email
if(isset($_POST['email']) && $_POST['email'] == 'sub') {
$_SESSION['offers'] = '1';
print 'this is 0';
}
};
?>