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

Asked

Viewed 758 times

0

I have two templates committing to the same file and I need to do an if() to check which algorithm should be run, but $_POST does not take the form name only the values.

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

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

1 answer

2


You can use a field of the type Hidden to identify which form is being submitted.

In 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
}
  • got it, it’s a really good alternative, thank you very much!

  • I’m glad I could help. :)

Browser other questions tagged

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