0

I am having several input fields with same name (there are several others input fields but this ones are important):

<input type=text name=title1 id=title1/>
<input type=text name=title2 id=title2/>
<input type=text name=title3 id=title3/>...

How can I count them (just input with name titlex)?

3
  • 6
    If you named them all name="title[]" instead, $_POST['title'] would be an array containing all of them. Is that an option? Commented Feb 25, 2013 at 22:25
  • Use the name title[] which will result in an array on within php. Commented Feb 25, 2013 at 22:25
  • 1
    @Wiseguy I have never thought in that direction. I guess I can put it in same array and then count new array. Commented Feb 25, 2013 at 22:27

1 Answer 1

3

If you cannot change the HTML, you could iterate, as long as the $_POST is set. Example:

$i = 1;
while (isset($_POST["title".$i])) {
  //handle input
  $i++;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.