PHP and Form names

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
redcube
Forum Newbie
Posts: 1
Joined: Mon Dec 20, 2004 10:41 am

PHP and Form names

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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...
}
Post Reply