Page 1 of 1

PHP and Form names

Posted: Mon Dec 20, 2004 10:48 am
by redcube
Hello,

Is it possible to use the form name as a variable in php?

Something like:

echo "\n<form name=\"myform\" action=\"./index.php?test=1\" method=\"POST\">";

Now how can I read the name of the form with php

I was hoping for something like $_POST['formname'] but does not work.

Thanks.

Posted: Mon Dec 20, 2004 11:26 am
by markl999
Nope. The form name isn't sent in the request headers.
You could store the form name in a hidden field instead though.

Posted: Mon Dec 20, 2004 1:57 pm
by rehfeld
if i have multiple forms on 1 page, i usually just name the submit button

but a hidden field works every bit as good.

Posted: Mon Dec 20, 2004 3:34 pm
by timvw
usually, 2 forms on a page also have differenct submit buttons...

Code: Select all

&lt;form action="" method="post"&gt;
&lt;input type="submit" name="form1" value="post form1" /&gt;
&lt;/form&gt;

&lt;form action="" method="post"&gt;
&lt;input type="submit" name="form2" value="post form2" /&gt;
&lt;/form&gt;
and then in your code you test

Code: Select all

if (isset($_POST['form1'])) {
  // do stuff with form1
}

if (isset($_POST['form2'])) {
  // do stuff with form2...
}