Detect which submit button was sent

0

Is there any way to detect in the php which submit button was sent? To create a function, if one is clicked execute one, if the other executes the other function?

<form method="post" action="" enctype="multipart/form-data">
  <input type="submit" name="F1" value="atualizar">
  <input type="submit" name="F2" value="deletar">
</form>
    
asked by anonymous 06.06.2018 / 18:11

2 answers

1
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
//algo postado

    if (isset($_POST['F1'])) {
       // atualizar
    } else {
       // deletar
    }

}

With the same button names:

 <input type="submit" name="qqname" value="atualizar">
 <input type="submit" name="qqname" value="deletar">

PHP

if ($_POST['qqname'] == 'atualizar') {
    // atualizar
}
else if ($_POST['qqname'] == 'deletar') {
    // deletar
}
    
06.06.2018 / 19:27
1

I made it as if it were for a checkbox type input, it looks like this:

<?php if(isset($_POST['F1'])){ echo 'f1 exite'; }else{ echo 'f1 não existe'; } if(isset($_POST['F2'])){ echo 'f2 existe'; }else{ echo 'f2 não existe'; } ?>

    
06.06.2018 / 18:48