I need to get the children of an element

Asked

Viewed 40 times

0

I need to get the value of inputs with ID nome and sobrenome, but when I use $_POST, it will return only the first, and I need all separately.

<form method="POST">
  <tr id = "0">
    <td>
      <input id="nome"/>
    </td>
    <td>
      <input id="sobrenome"/>
    </td>
  </tr>
  <tr id = "1">
    <td>
      <input id="nome"/>
    </td>
    <td>
      <input id="sobrenome"/>
    </td>
  </tr>
  <tr id = "2">
    <td>
      <input id="nome"/>
    </td>
    <td>
      <input id="sobrenome"/>
    </td>
  </tr>
  <input type="submit">
</form>
  • What do you mean by "catch"? Do you mean the value entered in the fields? If so, use the global $_POST of PHP.

  • @Andersoncarloswoss Updated question.

  • Okay. First, the attribute id define unique elements on the page, then create multiple elements with same id makes no sense. Second, define the attributes name of the fields and add [] at the end. For example: <input name="nome[]" />", in this way $_POST['name'] will be the list with all names filled in. That’s what you need?

  • Could you put that as an answer please ?? solved my problem.

  • 1

    Possible duplicate of Insert input value into array

1 answer

1


Ids are unique identifiers, cannot be duplicated.

Enter the attribute "name" in the input tag and set the value to "name[ ]". It would look like this:

<input name="nome[]"/>

This would create an array with all values filled in.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.