Detect which Submit button was sent

Asked

Viewed 98 times

0

Is there any way to detect in php which Submit button was sent? To create a function, if one is clicked run one, if the other runs 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>

  • And if you put both buttons with same name, it would not be enough to make $_POST['<nome>']?

2 answers

1

I did it like it was for a checkbox type input, it was 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'; } ?>

1


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

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

}

With same name of buttons:

 <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
}
  • It got wet that mine.

  • Like, it lowers my Cod.

Browser other questions tagged

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