By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

Get form name / id ??

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
*** 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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
*** 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

P: n/a
.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.