0

i use jquery.form to send a form, but in may case below how use this jquery plugin

$('#htmlForm').ajaxForm({ 
    target: '#htmlExampleTarget', 
    success: function() { 
        $('#htmlExampleTarget').fadeIn('slow');
        $('#htmlForm').hide();
    } 
});

for($i=1;$i<= 10;$i++){

//form $1

form name="form$i" action="blabla.php"

input type="text" name="name$i" />

input type="text" name="name$i" />

input type="submit" name="submit" /

}

1 Answer 1

0

Use class instead of id and loop through the forms. For the target take an id like #htmlExampleTarget1.

var i = 1;
$('.htmlForm').each(function () {
   var object = $(this);
   object.ajaxForm({
      target: '#htmlExampleTarget' + i, 
      success: function() { 
         $('#htmlExampleTarget' + i).fadeIn('slow');
         object.hide();
       }
   });
   i++;
});
Sign up to request clarification or add additional context in comments.

3 Comments

how did you integrated, did you changed your php code respectively and what exactly didn#t work (i.e. js error output)?
<script> $(document).ready(function(){ var i = 1; $('#htmlForm').each(function () { var object = $(this); object.ajaxForm({ target: '#htmlExampleTarget' + i, success: function() { $('#htmlExampleTarget' + i).fadeIn('slow'); object.hide(); } }); i++; }); }); </script> <?php $i=1; foreach ($data as $item) { <div id="htmlExampleTarget<?php echo $i;?>"></div> <form id="htmlForm" method="post" action="sendmail.php"> //form here </form> } ?> or you can view the demo at easyhired.com
Yes, because you are using an id not a class, as I showed in my example! Change <form id="htmlForm" ...> to <form class="htmlForm"> and your script from $('#htmlForm').each ... to $('.htmlForm').each ... and try again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.