Get form name / id ??

This is a discussion on Get form name / id ?? within the PHP Language forums, part of the PHP Programming Forums category; I have a form <form name="jim" id="jim" .......... > ......... </form> How do ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-13-2005
Rick
 
Posts: n/a
Default Get form name / id ??

I have a form

<form name="jim" id="jim" .......... >
.........
</form>

How do I get either the name or id from the form in PHP ?
--

Rick

Digital Printing
www.intelligence-direct.com - 01270 215550
Reply With Quote
  #2 (permalink)  
Old 01-13-2005
Roy W. Andersen
 
Posts: n/a
Default Re: Get form name / id ??

Rick wrote:
> I have a form
>
> <form name="jim" id="jim" .......... >
> ........
> </form>
>
> How do I get either the name or id from the form in PHP ?


You don't, unless you add it as a hidden input or a get-variable.

<input type="hidden" name="formname" value="myform">

And just grab that from $_POST['formname'] in your script.


Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Reply With Quote
  #3 (permalink)  
Old 01-13-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: Get form name / id ??

*** Rick wrote/escribió (Thu, 13 Jan 2005 12:48:44 +0000):
> <form name="jim" id="jim" .......... >
> ........
> </form>
>
> How do I get either the name or id from the form in PHP ?


The names are the keys in the $_GET or $_POST array.

foreach($_POST as $key => $value){
echo "<li>$key: $value</li>";
}

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Reply With Quote
  #4 (permalink)  
Old 01-13-2005
Rick
 
Posts: n/a
Default Re: Get form name / id ??

Alvaro G Vicario wrote:

> *** Rick wrote/escribió (Thu, 13 Jan 2005 12:48:44 +0000):
>> <form name="jim" id="jim" .......... >
>> ........
>> </form>
>>
>> How do I get either the name or id from the form in PHP ?

>
> The names are the keys in the $_GET or $_POST array.
>
> foreach($_POST as $key => $value){
> echo "<li>$key: $value</li>";
> }


Thats only for inputs contained within a form

--

Rick

Digital Printing
www.intelligence-direct.com - 01270 215550
Reply With Quote
  #5 (permalink)  
Old 01-13-2005
Rick
 
Posts: n/a
Default Re: Get form name / id ??

Roy W. Andersen wrote:

> Rick wrote:
>> I have a form
>>
>> <form name="jim" id="jim" .......... >
>> ........
>> </form>
>>
>> How do I get either the name or id from the form in PHP ?

>
> You don't, unless you add it as a hidden input or a get-variable.
>
> <input type="hidden" name="formname" value="myform">
>
> And just grab that from $_POST['formname'] in your script.


Bugger, thats what I am doing at the moment, was hoping there was a better
way :/

--

Rick

Digital Printing
www.intelligence-direct.com - 01270 215550
Reply With Quote
  #6 (permalink)  
Old 01-13-2005
Roy W. Andersen
 
Posts: n/a
Default Re: Get form name / id ??

Rick wrote:
> Roy W. Andersen wrote:
>
>><input type="hidden" name="formname" value="myform">
>>
>>And just grab that from $_POST['formname'] in your script.

>
> Bugger, thats what I am doing at the moment, was hoping there was a better
> way :/


Sending it as a POST with the rest of the form is pretty straight
forward and simple. If you're doing a foreach() loop on the $_POST array
on the serverside and don't want to do whatever you do to the form data
with that field, just issue an if/else or switch-statement to filter it
out. Either that, or you can start by grabbing the $_POST['formname']
followed by an unset($_POST['formname']) to avoid it carrying into the
code you got further down :)


Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Reply With Quote
  #7 (permalink)  
Old 01-13-2005
Alvaro G Vicario
 
Posts: n/a
Default Re: Get form name / id ??

*** Rick wrote/escribió (Thu, 13 Jan 2005 13:00:55 +0000):
> Thats only for inputs contained within a form


You are right, I misunderstood you. The answer is: you cannot. That info is
not sent to the server. Just add an extra hidden field.

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Reply With Quote
  #8 (permalink)  
Old 01-13-2005
Michael Fesser
 
Posts: n/a
Default Re: Get form name / id ??

.oO(Rick)

>Roy W. Andersen wrote:
>
>> You don't, unless you add it as a hidden input or a get-variable.
>>
>> <input type="hidden" name="formname" value="myform">
>>
>> And just grab that from $_POST['formname'] in your script.

>
>Bugger, thats what I am doing at the moment, was hoping there was a better
>way :/


Nope. The name attribute for the form element is just there for
backwards compatibility (according to the spec, personally I've never
used it), so it's rather useless and not submitted to the server at all.

Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0