0
<form class="form-horizontal" method="post" id="sponsor" name="sponsor" onsubmit="return ajaxSubmit();" >   
    <input type="text" class="form-control"  id="sponsor_name" name="sponsor_name" placeholder="Enter Name"/>   
    <input type="submit" class="btn btn-default" name="sponsor_form" value="Register" />                
</form>
function ajaxSubmit(){
    // fetch where we want to submit the form to
    var url = url;
    // fetch the data for the form
    var email = $('#sponsor #email').val();
    // setup the ajax request

    $.ajax({
        url: url,
        method:'POST',
        data: {email:email},
        success: function(data) {
            if(data!=0){
                alert('ifenter');
                $('#msg_section').html('The email has already registered with '+data+' plan <br/> <button type="button" class="btn btn-default form_sponsor" id="form_sponsor" name="form_sponsor" onclick="submitform()">Click Here to Continue</button>');

                $('#msg_section').css('display','block');
                $('#form_sponsor').css('display','block');
                return false;
            }else{
                alert('enter');
                $('#msg_section').css('display','none');
                $('.form_sponsor').css('display','none');
                $('#msg_section').html('');
                return true;
            }
        }
    });
    return false;
}

Return true it's suppose to go in isset($_POST['sponsor_form']). But its not working any help is accepted.Th e ajax is not working.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    There's no `id="email"` in the form. – Barmar Dec 29 '15 at 18:11
  • 4
    @Cᴏʀʏ Please don't recommend synchronous AJAX, it's deprecated. Explain how to do it correctly. – Barmar Dec 29 '15 at 18:12
  • Did you verify the values that are fetched by javascript, are they matching with the entered values? – Manikiran Dec 29 '15 at 18:13
  • @Barmar: Point taken, comment removed. Though the "correct" way is going to be hard to explain to someone who doesn't understand what "asynchronous" means. David's link is probably a good start. – Cᴏʀʏ Dec 29 '15 at 18:15
  • I was going to close this as a duplicate of that as well. But I can't really figure out what this code is trying to do with the return value. He's already submitting the form using AJAX, so it doesn't need to be submitted again if the function returns true. – Barmar Dec 29 '15 at 18:21
  • @Barmar the site is not allowing me to copy entire code.My code is working correctly.I am getting alert basically i want on return true to get the form submit via post. – Abhishek Singh Dec 29 '15 at 18:21

0 Answers0