Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

determine number of entries

0 views
Skip to first unread message

questi...@hotmail.com

unread,
Jan 29, 2008, 7:58:14 AM1/29/08
to
Hello,

I have a form in which the user can add more textboxes as need be.

Ing1
Ing2
Ing3
....

There could be 1 input or there could be 30...

How can I, in php, determine the number of input controls so that I
can then loop through them one by one and process their data?

Thank you,

QB

questi...@hotmail.com

unread,
Jan 29, 2008, 8:50:21 AM1/29/08
to
After some tinkering, I have now setup a hidden input which houses the
count of the number of entries and it gets updated through the
javascript which dynamically alters the page. I can then use it value
in my php code as my counter.

If there is a better approach I would be interested.

QB

la...@portcommodore.com

unread,
Jan 29, 2008, 9:53:19 AM1/29/08
to

I myself go for displaying the max necessary and then checking each
for content when processing. Though it may put a big field of text
boxes on your form, but if the for is for data-entry savvy people
they'll appreciate not having to use extra controls to routinely add
something they need.

ZeldorBlat

unread,
Jan 29, 2008, 11:13:28 AM1/29/08
to

Use arrays. If your form elements look like this:

<input type="text" name="foo[]" />

Then they will be available as an array when you process it:

foreach($_SERVER['POST']['foo'] as $key => $value) {
//do something with each one
}

And you can easily know how many there are:

count($_SERVER['POST']['foo'])

0 new messages