SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    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>
    Here is what I have to post the VALUES, but I also need to integrate the input NAMES as well from above:
    PHP Code:
    if($_POST){
        foreach(
    $_POST as $value){
            echo 
    $value;
        }


  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    if($_POST){ 
        foreach($_POST as $name=>$value){ 
            echo $name.'='.$value; 
        } 
    }

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, i just figured it out...

  4. #4
    SitePoint Addict Wildhoney's Avatar
    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!
    TalkPHP.com - The Friendly PHP Community

    Watch Reaper Online - Watch Chuck Online


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •