find name of form

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
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

find name of form

Post by bimo »

I was wondering if the name of a submitted form is kept in GET or POST or REQUEST. If not, is there any way other than javascript to do find out which form was submitted without checking the form's structure against some kind of pattern.

Thanks,

h
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you could do

Code: Select all

<form name="coolba" action="script.php?f=coolba" method="post">
then just get the form name from $_GET['f']

if you put that on all your forms you will be supra solid

edit: alternativly you could do a input type=hidden kinda deal with the form name in each form, which might be quite a bit better
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

Rigght, I was wondering where the form name is in the POST array. Is it something like $_POST['name'] or does it have a different key?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

the form name is NOT passed with the posted data. you could do what shiznatix suggested (either suggestoin would work), or you could name your submit buttons and use some kind of conditional statement to determine which from was posted by determining which button was clicked.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

You would be better off using a hidden input tag for that.

Code: Select all

<input type="hidden" name="form_name_check" value="my form name">
You can change the value to a php variable so it can be changed. Then just check $_POST['form_name_check'] to see what form it was.

Another way would be to do something like this...
User avatar
bimo
Forum Contributor
Posts: 100
Joined: Fri Apr 16, 2004 11:18 pm
Location: MD

Post by bimo »

Thanks...
Post Reply