loop through all form elements

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

loop through all form elements

Post by yaron »

Hello all,
I have a form with an unknown number of text fields in it.
once submited i need my php script to get all those variables i.e. the text input names from the form.

is that possible or I have to specify each name one by one...?

Thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you're using the $_POST array it's easy to deal with varying numbers of fields, for example:

Code: Select all

foreach ($_POST as $key => $value) {
    echo 'Field name: <b>'.$key.'</b> and value: <b>'.$value.'</b><br />';
}
Mac
yaron
Forum Contributor
Posts: 157
Joined: Fri Aug 22, 2003 8:40 am

Post by yaron »

Hey,
Thanks... got it myself and just wanted to write the answer but you beat me to it.

Thanks a lot...
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Don't you know, she's the fastest typer ;)

-Nay
Post Reply