#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    UK
    Posts
    27
    Rep Power
    0
    When passing form inputs to another php page, I know that a form field named field1 will pass the value to the next page in a variable named $field1.

    However, is it possible to pass the field directly into an array? I ask this, because my forms are generated dynamically, and each form field is numbered - so I would like to pass the values into the appropriately numbered slot in the array for the next page.

    Cheers,
    Ben.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    Yup, you can use arrays in <FORM> tags:

    <form..>
    <input type=... name=arrvalue[1] value=..>
    <input type=... name=arrvalue[2] value=..>
    <input type=... name=arrvalue[3] value=..>
    <textarea name=arrvalue[4] ...></textarea>

    and so on. You can use any of PHP's methods of storing arrays -- such as calling it arrvalue[value1] and so on. It's particularly(sp?) useful when you do forms with a lot of variables, since submitting arrays makes it alot easier for you to keep track of what goes where.

    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson

    [This message has been edited by cka (edited September 28, 2000).]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    114
    Rep Power
    15
    That's more or less correct, except that it wouldn't work. You can't assign an index when you're using a control array. It should just be name=arry[] with all members of that control array having the same name. PHP will automatically assign indices to the returned array.
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    sorry billyo but it would/does work - apart from when you assign checkboxes or single radio buttons as arrays, if a box is not checked then that index is never created and you get an illeagal string index error , but for other fields arrays work fine as above.

    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    114
    Rep Power
    15
    I stand corrected. Thanks.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    UK
    Posts
    27
    Rep Power
    0
    I've used that method, and simply tested for the presence of the variable to see if it was checked or not - for example, if checkbox a[1] and a[3] are checked, and a[2] and a[4] are not - then I do if($a[1]){...} and so on.

    Thanks all for the help.
    Ben.

Similar Threads

  1. reset single input field not form
    By darkane in forum HTML Programming
    Replies: 2
    Last Post: January 31st, 2004, 02:11 PM
  2. JavaScript: DOM: form input setAttribute problem
    By fsantiago in forum JavaScript Development
    Replies: 1
    Last Post: January 30th, 2004, 05:19 PM
  3. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM
  4. access form sql input
    By xyfix in forum Database Management
    Replies: 3
    Last Post: January 21st, 2004, 07:13 PM
  5. read form input values
    By zapounidous in forum Java Help
    Replies: 2
    Last Post: January 14th, 2004, 08:16 AM

IMN logo majestic logo threadwatch logo seochat tools logo