提交按钮高于循环表输入字段

提交按钮高于循环表输入字段

问题描述:

I have got in trouble when I was going to show (print is more suitable) a list of input field within form. According to normal situation, there will be a Submit button below it in order to submit the form to (any pages).

Then, I was so confused., because when I use this below code to loop.

<table>
<form>
for($a=1; $a<=10; $a++){
  <tr>
    <td>
        <div class="form-group">
          <input class="form-control" type="text" name="name<? echo $a; ?>" required="required"/>
        </div>
    </td>
    <td>
        <div class="form-group">
           <input  class="form-control" type="text" name="url<? echo $a; ?>" required="required"/>
        </div>
    </td>
</tr>
}
<input type="submit" value="Submit" class="btn btn-primary"/>
</form>
</table>

Tadaa...then it shows: enter image description here

And the Submit button is on the top of the form?! Can any help me to fix it?

Or...at least some reason?

Update your code like

<tr>
    <td colspan="2">
      <input type="submit" value="Submit" class="btn btn-primary"/>
   </td>
</tr>

it will display submit button below the input field.

You have incorrect order of html tags.

<table>
    <form>
        <tr>
        ...
        </tr>
        <input type="submit" value="Submit" class="btn btn-primary"/>
    </form>
</table>

<table> tag can only contain (in this particular order)

  • an optional <caption> element,
  • zero or more <colgroup> elements,
  • an optional <thead> element,
  • either one of the following:
    • zero or more <tbody> elements
    • one or more <tr> elements
  • an optional <tfoot> element

Try reordering your elements like this:

<form>
    <table>
        <tr>
        ...
        </tr>
    </table>
    <input type="submit" value="Submit" class="btn btn-primary"/>
</form>