469,330 Members | 1,284 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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
Jul 17 '05 #1
7 40119
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
Jul 17 '05 #2
*** 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
--
Jul 17 '05 #3
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
Jul 17 '05 #4
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
Jul 17 '05 #5
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
Jul 17 '05 #6
*** 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
--
Jul 17 '05 #7
.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
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Scott Navarre | last post: by
4 posts views Thread by Edward Lim | last post: by
6 posts views Thread by Java script Dude | last post: by
2 posts views Thread by Jeff Baker | last post: by
2 posts views Thread by ej | last post: by
4 posts views Thread by ashore | last post: by
3 posts views Thread by scripteaze | last post: by
9 posts views Thread by scripteaze | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.