SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting NAME attribute of form fields

    Hey guys,

    I was just wondering if it's possible to obtain the name attribute of my form fields?

    Eg. Let's say the form is a mixture of <select> and <input />.
    <select name="my_select"> and <input name="my_input" />"
    Note the names are not my_input[], it's just 'my_select'. Can the name attribute be displayed?

    or do i have to put them in an array (my_select[]) ?? If so, what would be the easiest way to do it?

    any help will be appreciated.

    asT.

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use array_keys() on your GET / POST data:

    PHP Code:
    print_r(array_keys($_POST)); 

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <select name='mySelectBox' size='1'>
    .
    .
    </
    select>
    .
    .
    # and your other question...
    <input type='text' name='Username' ...>
    .

    Once the FORM has been submitted you can get at the data sent by the FORM using PHPs $_POST[], as such:

    PHP Code:
    $Username = (string) $_POST['Username']; 
    With SELECT though I'm not sure ? I'd need to see about this myself, though some members would say you need to give your SELECT box name as an array though I don't.

    My thinking being that the FORM can only return one value out of the possible total - from OPTIONs obviously.

    Though this would be a problem - and you no doubt would need to give an array - if you've set the attribute MULTIPLE to your SELECT box, if you follow me ?

    I've yet to use MULTIPLE myself so I can't give an answer there 8)

    Hope this helps though ?

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies guys.

    Chris, that was exactly what i was looking for. cheers

    Doc, I'm aware of how $_post works, and you are right, the <select> , the value is obtained from the <option value="">. That's what I use anyway. Makes it easier for me.

    I needed to retrieve the name attribute, not the value inserted by the user. But it's all good

    cheers guys
    ast.

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I understand..... LoL 8)

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <select> only needs to be submitted as an array if you use multiple select box. (For some reason, somebody got the idea that you always have to use it for <select>'s...)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •