Only first form ID is sending!

Asked

Viewed 34 times

0

I’m trying to send a post without refresh with this method below but only sends the first form the second it redirects to page, I’m with the Forms inside a while PHP

$(function($) {
    $('#enviaadv').submit(function() {

        $(this).ajaxSubmit(function(resposta) {
            if (!resposta){
                $onclick = showadv('bottom','left',resposta);
            }
            else
            {
                $onclick = showadv('bottom','left',resposta);
            }

        });

        return false;

    });
});
</script>   
<form id="enviaadv" action="functions/advogadoresponsavel.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="advid" value='awdawd'>
    <input type="hidden" name="advnome" value='awdawd'>
    <input type="hidden" name="idunico" value='adawdaw'>

        <button class="btn btn-success btn-link btn-just-icon btn-sm">
            <i class="material-icons">person_add</i>
        </button>
</form> 
<form id="enviaadv" action="functions/advogadoresponsavel.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="advid" value='dawd'>
    <input type="hidden" name="advnome" value='awdawd'>
    <input type="hidden" name="idunico" value='awdawd'>

        <button class="btn btn-success btn-link btn-just-icon btn-sm">
            <i class="material-icons">person_add</i>
        </button>
</form> 
  • Ids must be unique!

  • i need to put the script inside the while?

  • While? It makes even less sense, because there is no while in your code. If you want to "repeat an id", use class instead. Anyway, it’s strange to have two presses.

  • has worked http://prntscr.com/jwfd6l but has no better method of doing so?

  • Leave the script out of the loop and change the selector to $('form').submit(function(){... the form that is sent will be automatically captured.

  • But I don’t want you to take all the Forms from the page just the uqe are in the loop

Show 1 more comment

1 answer

0

First FORM:

<input type="hidden" name="idunico" value='adawdaw'>

According to FORM:

<input type="hidden" name="idunico" value='awdawd'>

The ids are the same. Try changing the name, for example, idunico2.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.