Putting more than one SUBMIT input into an HTML form

Asked

Viewed 635 times

0

I have on my page a form (form) with an already determined action and an input button.

<form id="educForm1" name="educForm1" action="<?php echo ROOT . 'educacao' ?>/enviaemail" method="post" enctype="multipart/form-data">
...
    <input id="enviaEmail" name="enviaEmail" type="submit" class="textDescricaoSobre font13" value="Criar Evento" style="cursor: pointer; width: 90px;" />
</form>

By pressing this sent Mail button, it should save the form data to the database table and automatically send an email with the recorded data.

I would like to put a second Ubmit, which only sent the e-mail and did not record in the bank. The first Ubmit would only save the data, but should not refresh the page in the action (action=php echo ROOT . 'education' /enviaemail).

What could I do? Change the action? Put button instead of input? I’m open to suggestions.

  • Voce would have to handle the submissions via javascript, making each button call a function

  • 3

    You can use the same Ubmit with a checkbox indicating whether or not to save the information to the database.

1 answer

1

Use the checkbox or select(yes/no) in the form to indicate whether or not the record should be saved to the database.

As sending email is mandatory, divide the code into at least two functions one that writes to the bank and the other that sends the email, so the main flow of the program is very simple.

Something like:

<?php
   $msg = enviarEmail($dadosForm); //retorna uma string sucesso ou falha.
   if($_POST['insert'] == 'sim'){
      gravarNoBanco($dadosForm);
   }

   echo $msg;

Browser other questions tagged

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