0

This is the html form:

<form id="contactRefer" method="POST" action="submit.php">
<input type="email" name="email[email-0]" required >
<input type="text" name="mobile[mobile-0]" required >
.
.
.
<input type="hidden" value="2" id="count" name="count">
<a style="cursor:pointer;" id="more-friends">Add More Friends </a>
<button class="btn btn-success" type="submit" id="frmSubmit">Send</button>

The jQuery I am using is as follows. Please note that I want to use dynamically added input box also.:

$("#more-friends").click(function(){
    var i = parseInt($('#count').val())+1;
    $('.new-friends').append('<div class="col-md-12"><div class="col-md-6"><div class="form-group"><input type="email" name="email[email-'+i+']" placeholder="Enter Email Id" class="form-control" data-validetta="email"></div></div><div class="col-md-6"><div class="form-group"><input type="text" name="mobile[mobile-'+i+']" placeholder="Enter Mobile Number" class="form-control" data-validetta="minLength[10],maxLength[15]"></div></div></div>');
    $('#count').val(i);
});

$("#frmSubmit").on('click', function(){
    $.ajax({
      type  : "POST",
      url   : "submit.php",
      data  : $("#contactForm").serialize(),
      datatype : 'text',
      success: function(data) {     
        alert(data);
      }
    });         

});

I want to send the whole form data using mail method in php. But before that I also want to get all the values in a string. I am not able to get that php part which converts all the POST data into php array.

2
  • 1
    your form id is contactRefer not contactForm it shoud be $("#contactRefer").serialize(), Commented Nov 4, 2015 at 9:33
  • What a stupid I am! Thanks bro! @Osama Jatawe Commented Nov 4, 2015 at 9:37

2 Answers 2

3

your form id is contactRefer not contactForm it shoud be $("#contactRefer").serialize()

$("#frmSubmit").on('click', function(){
    $.ajax({
      type  : "POST",
      url   : "submit.php",
      data  : $("#contactRefer").serialize(),
      datatype : 'text',
      success: function(data) {     
        alert(data);
      }
    });         

})
Sign up to request clarification or add additional context in comments.

1 Comment

if this is answer solved your problem please accept it, thanks
1

Your Form ID is wrong

$("#frmSubmit").on('click', function(){
    $.ajax({
      type  : "POST",
      url   : "submit.php",
      data  : $("#contactRefer").serialize(),
      datatype : 'text',
      success: function(data) {     
        alert(data);
      }
    });         

});

In PHP you will get it like,

echo $_POST['email']['email-0'];
echo $_POST['mobile']['mobile-0'];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.