$ _POST take the form name="this name" ...

0

I have two forms submitting to the same file and I need to do an if () to check which algorithm should be executed, but $ _POST does not take the name of the form just the values.

<form name="frmCadastro" method="post" action="../_controllers/ccontatos.php">

<form name="frmGrupos" method="post" action="../_controllers/ccontatos.php">
    
asked by anonymous 18.11.2016 / 02:49

1 answer

2

You can use a hidden field to identify which form is being submitted.

No HTML:

<form name="frmCadastro" method="post" action="../_controllers/ccontatos.php">
  <input type="hidden" name="form_name" value="cadastro" />
</form>

<form name="frmGrupos" method="post" action="../_controllers/ccontatos.php">
  <input type="hidden" name="form_name" value="grupos" />
</form>

In PHP:

if ($_POST['form_name'] == 'cadastro') {
  // formulário cadastro
} else if ($_POST['form_name'] == 'grupos') {
  // formulário grupos
}
    
18.11.2016 / 03:28