表单不接受我表单中的所有输入行(输入名称丢失(

I have this code and I need to get the count of inputs that I put in inserting the rows and input text form. Please can anyone help me?

function myFunction() {
  var table = document.getElementById("mytable");
  var rowCount = table.rows.length;
  var row = table.insertRow(rowCount - 1);

  var cell1 = row.insertCell(0);
  var cell2 = row.insertCell(1);

  cell1.innerHTML = table.rows[0].cells[0].innerHTML;
  cell2.innerHTML = table.rows[0].cells[1].innerHTML;
}
<table id="mytable">
  <form method="POST">
    <tr>
      <td>
        <input name="s1[]" type="text" />
      </td>
      <td>
        <input name="s2[]" type="text" />
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <input type="submit" name="submit" value="insert" />
      </td>
    </tr>
  </form>
</table>

<button onclick="myFunction()">more</button>

<?php if(isset($_POST[ 'submit']))
  {
    $count = count($_POST[ 's1']); 
    echo "<script>alert('".$count. "');</script>"; 
  } 
?>

</div>

Perhaps you should put the table inside the form:

<form method="POST">
    <table id="mytable">
        <tr>
            <td>
                <input name="s1[]" type="text" />
            </td>
            <td>
                <input name="s2[]" type="text" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" name="submit" value="insert" />
            </td>
        </tr>
    </table>
</form>

A form is not allowed to be a child element of a table, tbody or tr.

You can have an entire table inside a form. You can have a form inside a table cell. You cannot have part of a table inside a form.

Use one form around the entire table. Then either use the clicked submit button to determine which row to process (to be quick) or process every row (allowing bulk updates).

Everything fine. Put your <form> & </form> outside table. <table></table> should be inside <form></form>

<form method="POST">
    <table id="mytable">
        <tr>
          <td>
            <input name="s1[]" type="text" />
          </td>
          <td>
            <input name="s2[]" type="text" />
          </td>
        </tr>
        <tr>
          <td colspan="2">
            <input type="submit" name="submit" value="insert" />
          </td>
        </tr>
    </table>
</form>

For more info, check this