One BUTTON to save data from all Foms!

Asked

Viewed 76 times

-1

I have an extensive form with some tabs and in each tab there is a form with "post" method. I would like to create a "finish" BUTTON in the last tab that saved all the data entered in all form form, as I do?

Note: Due to the form be mt great, there is no way to put here tds the codes so I will summarize and if you need some code I add in the question.

inserir a descrição da imagem aqui

The shape of the tabs is like this:

<form action="/Pasta/SalvarInquerito" method="post" id="FormInquerito"></form>
<form action="/Autor/Salvar" id="formAutor" method="post"></form>
<form action="/Pasta/SalvarCrime" method="post" id="FormCrime"></form>
<form action="/Filhos/Salvar" id="formFilho" method="post"></form>
<form method="post" id="PericiaForm" action="/Pasta/SalvarPericia"></form>
<form action="/Pasta/SalvarVitima" method="post" id="FormVitima"></form>

The button I use in each tab to save the data entered in the tab:

<button type="submit"
                id="btnSalvar"
                form="FormVitima"
                class="btnSalvarGreen">
            SALVAR
</button>
  • 1

    Do you really need to have multiple presses? Regardless of how many sessions you can leave all in one form since you want to save all at once and not one at a time.

  • 1

    I think you’re looking for that method Htmlformelement.Ubmit(). In case it would be an external button to the forms that would call this method for each of the Forms? Confirm so that you can submit an answer to me has become a little vague.

  • @Augustovasques Yes exactly that!

  • @Mizrainphelipesá, already answered and the answer seems appropriate.

1 answer

1

I believe that one of the ways would be using a simple javascript (and if necessary I can write an example in jQuery).

On the button you created place an event onclick with a function name and change the type of Submit for button so that the DOM control is in JS. As in the example below:

<input type="button" id="btnSalvar" class="btnSalvarGreen" value="SALVAR" onclick="salvarForms()" />

In javascript code, do an action Submit for every form you want based on your ID:

salvarForms = function(){
   document.getElementById("formInquerito").submit();
   document.getElementById("formCrime").submit();
   .
   .
   .
}

Ready! You will probably be able to save multiple Foms this way. Then tell me if it worked, ok?

  • 1

    Okay, I’m gonna test here!

  • I tested your code, I did exactly the same but when I click on this error on the console: Uncaught Typeerror: Cannot read Property 'Submit' of null at salvarForms (Files:588) at Htmlinputelement.onclick (Files:492)

  • You have checked whether the form fields are filled in?

  • Yes, they are filled, but this giving error.

  • 2

    If you’re making a mistake Cannot read property 'submit' of null is because when you do the getElementById() the id passed as parameter is not being found in the document probably the id is spelled wrong.

Browser other questions tagged

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