Form within an html Form

1

A doubt that may be simple, but I had no choice:

I have a main html FORM, which captures all the data in a table, the problem is that there are images uploaded inside that form, and that upload is instantaneous without the form submit (made with AJAX jquery), ie , I need another form to call the php file that treats the image, the problem is that it gets a form inside the form, and the forms do not nest, the form does not work larger (the img is loaded but the larger form does not generate the submit),

Does anyone have any ideas or suggestions?

ps: I did not post code because I do not see need, it's a form inside another and the parent form does not work.

    
asked by anonymous 01.08.2016 / 19:16

1 answer

2

Just to have an answer. Here is the HTML code:

<form>
  <input type="text" class="input-form" name="input_pai_0" value="FormPai">
  <form>
      <input type="text" class="input-form" name="input_filho_0" value="FormFilho">
  </form>
  <button class="btnEnviar">Enviar</button>
</form>

Follow js:

$(document).ready(function(){
    $(".btnEnviar").click(function(){
        //Validações

        var dados = {};
        $(".input-form").each(function(){
            dados[$(this).attr("name")] = $(this).val();
        });

        console.log(dados);

        $.post('/echo/json/', dados, function(data){
            alert('Dados enviados com sucesso!');
        });
    });
});

And example link link

    
02.08.2016 / 22:03