SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Dec 5, 2007, 16:13 #1
- Join Date
- Aug 2004
- Location
- San Clemente, CA
- Posts
- 859
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
a script to echo form element names
I am working on a dynamic "form helper" script to echo form element names of a submitted form? My goal is to have it output the names and values of each element. I have the values figured out.. need help with the element names.
How can I have an array print exactly "name", "email" and "phone" if this is submitted?
HTML Code:<form name="form1" method="post" action=""> <input name="name" type="text" /> <input name="email" type="text" /> <input name="phone" type="text" /> <input type="submit" name="submit" value="submit" /> </form>
PHP Code:if($_POST){
foreach($_POST as $value){
echo $value;
}
}
-
Dec 5, 2007, 16:40 #2Code php:
if($_POST){ foreach($_POST as $name=>$value){ echo $name.'='.$value; } }
-
Dec 5, 2007, 16:47 #3
- Join Date
- Aug 2004
- Location
- San Clemente, CA
- Posts
- 859
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, i just figured it out...
-
Dec 5, 2007, 16:58 #4
- Join Date
- Apr 2006
- Location
- Nottingham
- Posts
- 246
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I remember when I was starting out with PHP, it took me several months to realise you could also get the key in the foreach loop. Prior to realising that I was using array_flip to flip the keys and values and then flipping them backing again. Oh dear!
Bookmarks