html数字输入文件

时间:2015-12-13 04:49:15

标签: php html wordpress

我有以下代码:

<!DOCTYPE html>
<html>
  <body>
     <form action="<?=$PHP_SELF?>" method="post"> 
     <table style="width:100%">
      <tr>    
        <td>
          <form><input type=number min="0" max="19" name="score1" /></form> 
        </td>
        <td>
          <form><input type=number min="0" max="19" name="score2" /></form> 
        </td>     
      </tr>
   </table>
  <?php 
    global $score1;
    global $score2;
    echo "Score 1= " . $_POST['score1']. "    ";
    echo "Score 2= " . $_POST['score2']. "    ";
  ?> 
  <input type="submit"/> 
   </form>
  </body>
</html>

score1正确显示,但score2始终为空。我在wordpress模板中运行它,它可能导致这个问题,还是别的什么?

2 个答案:

答案 0 :(得分:1)

因为您在所有文本输入之前和之后打开和关闭表单。

试试这个:

<!DOCTYPE html>
<html>
<body>
    <form action="<?=$PHP_SELF?>" method="post"> 
        <table style="width:100%">
            <tr>    
                <td><input type=number min="0" max="19" name="score1" />  
            </td>
            <td>
                <input type=number min="0" max="19" name="score2" />    
            </td>     
            </tr>
        </table>
        <?php 
            global $score1;
            global $score2;
            echo "Score 1= " . $_POST['score1']. "    ";
            echo "Score 2= " . $_POST['score2']. "    ";
        ?> 
        <input type="submit"/> 
    </form>
</body>
</html>

答案 1 :(得分:1)

  1. 您无法为每个<td>
  2. 创建表单
  3. 同样为了方便调配,请将PHP代码放在顶部,然后html个文件
  4. 以下更改

    <table style="width:100%">
          <tr>    
            <td><form> <input type=number min="0" max="19" name="score1" />  
            </form> 
            </td>
            <td><form> <input type=number min="0" max="19" name="score2" />    
            </form> 
            </td>     
          </tr>
       </table>
    

    <?php 
        global $score1;
        global $score2;
        echo "Score 1= " . $_POST['score1']. "    ";
        echo "Score 2= " . $_POST['score2']. "    ";
      ?> 
    
    
            <form action="<?=$PHP_SELF?>" method="post"> 
            <table style="width:100%">
                  <tr>    
                    <td><input type=number min="0" max="19" name="score1" /></td>
                    <td><input type=number min="0" max="19" name="score2" /></td>     
                  </tr>
               </table>
    
        <input type="submit"/> 
            </form>