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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
*** 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 -- |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
*** 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 -- |
|
|||
|
.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 |