【问题标题】:PHP Form not posting all fieldsPHP表单未发布所有字段
【发布时间】:2013-04-25 16:40:46
【问题描述】:

我有一个奇怪的问题,我无法理解。

我有以下表单,当我单击提交时,我没有获取或发布表单中的所有字段。只有两个字段被选中 - isnew=true action=object &submit=Start

<form name="newOffer" action="/auth/dashboard" method="post">
                                <td><?php echo form_hidden('isnew', 'true');?><?php echo form_hidden('action', 'object');?><input type="text" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge"></td>
                                <td><input type="text" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item"></td>
                                <td><input type="text" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5"></td>
                                <td><span class="label label-danger">Inactive</span></td>
                                <td><?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?></td>
                             </form>

【问题讨论】:

    标签: php forms post get field


    【解决方案1】:

    您需要为每个 INPUT 元素添加 NAME 属性 - 代替 ID 属性或添加到 ID 属性。

    例如

    <form name="newOffer" action="/auth/dashboard" method="post">
        <td>
            <?php echo form_hidden('isnew', 'true');?>
            <?php echo form_hidden('action', 'object');?>
            <input type="text" NAME="newOfferItem" id="newOfferItem" placeholder="Offer Free Item" class="input-xlarge">
        </td>
        <td>
            <input type="text" NAME="newOfferText" id="newOfferText" placeholder="Offer Description" class="input-xlarge" rel="tooltip" title="Description How to get free item">
        </td>
        <td>
            <input type="text" NAME="newOfferFreeOn" id="newOfferFreeOn" placeholder="Stamps for free item" class="input-xlarge" rel="tooltip" title="Number only. Ex. 5">
        </td>
        <td>
            <span class="label label-danger">Inactive</span>
        </td>
        <td>
            <?php $attributes = 'class = "btn btn-success"'; echo form_submit('submit', 'Start', $attributes);?>
        </td>
    </form>
    

    【讨论】:

      【解决方案2】:

      始终在input 元素中添加name 属性。
      这是一个给你的例子..

      index.html

      <form method="POST" action="process.php">
          <input type="text" name="username" value="">
          <input type="password" name="password" value="">
          <input type="submit" name="submit" value="login">
      </form>
      

      process.php

      <?php
      
      // checking if submit is pressed
      
      if (isset($_POST['submit'])) {
      
          // assigning posted values
      
          $username = $_POST['username'];
          $password = $_POST['password'];
      
          // testing
      
          echo $username . "<br>";
          echo $password;
      }
      
      ?>
      

      【讨论】:

        猜你喜欢
        • 2012-02-16
        • 1970-01-01
        • 2020-05-15
        • 1970-01-01
        • 2015-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多