How to send two actions in a single form?

2

Hello, I have a pay-as-you-go button on my site, but when I click on it, I want it to take the form data and send it to another page (and then put it in the database). So when you click the payroll button it will send two actions. (one for the pagseguro and another for my bd.

Payroll form.

<!-- INICIO FORMULARIO BOTAO PAGSEGURO -->
<form action="https://pagseguro.uol.com.br/checkout/v2/cart.html?action=add" method="post" onsubmit="PagSeguroLightbox(this); return false;">
<!-- NÃO EDITE OS COMANDOS DAS LINHAS ABAIXO -->
<input type="hidden" name="itemCode" value="DF45A4323B3BA53224E48FBA638D48CE" />
<input type="image" src="https://p.simg.uol.com.br/out/pagseguro/i/botoes/pagamentos/209x48-pagar-assina.gif"name="submit" alt="Pague com PagSeguro - é rápido, grátis e seguro!" /> 
</form>
<script type="text/javascript" src="https://stc.pagseguro.uol.com.br/pagseguro/api/v2/checkout/pagseguro.lightbox.js"></script>
   

Siteform.

<formmethod="post" action="">
            <table class="tb">
                <tr><td>Nome: </td><td><input type="text" name="nome"></td></tr>
                <tr><td>E-mail: </td><td><input type="text" name="email"></td></tr>
                <tr><td>Telefone: </td><td><input type="text" name="telefone"></td></tr>
            </table>
 </form>

I'm thinking of putting both in the same form, but the question continues. How to submit to two different pages via action?

    
asked by anonymous 06.07.2015 / 15:11

2 answers

2

Hello,

You can only submit the form once to the url informed. To solve your problem you can send these requests via ajax.

link

Example:

<form>
Primeiro nome: 
<input type="text" name="firstname">
<br>
Último nome: 
<input type="text" name="lastname">
<input type="button" value="Save" id="saveName">
</form>

Js script:

$('#saveName').click(function (event) {
    event.preventDefault();
    $.ajax({
        contentType: 'application/json'
        data: $("form").serialize(),
        type: 'POST',
        url: '<SUA URL>'
    }).done(function (data) {
       //Tratar algum retorno da sua aplicação
    });

    $.ajax({
        contentType: 'application/json'
        data: $("form").serialize(),
        type: 'POST',
        url: '<URL PAGSEGURO>'
    });
});
    
06.07.2015 / 16:21
2

By the W3C standard, once you submit a form, you have already navigated and can no longer submit the exact same form, so you define only one target in the action. A workaround for your case might be:

  • First you send the data of your form via Ajax to save to your bank
  • Then you can submit the form normally for the payment, as you are doing now
  • 06.07.2015 / 15:31