简体   繁体   English

带有复选框和文本字段的动态php网格上的验证

[英]Validations on dynamic php grid with check boxes and text fields

在此处输入图片说明

I have following data to show from data base, it is no ok. 我有以下数据要从数据库中显示,这不行。

<table class="table-style-one" width="90%" border="0" cellspacing="1" cellpadding="1" style="margin:0 auto;">

              <thead style="color:black;">
                <th style="text-align:center;">S.N</th>
                <th style="text-align:center;">PO REFERENCE</th>
                <th style="text-align:center;"><strong>ITEM NAME</strong></th>
                <th style="text-align:center;"><strong>UNIT</strong></th>
                <th style="text-align:center;"><strong>QUANTITY IN STOCK</strong></th>
                <th style="text-align:center;"><strong>FROM THIS</strong></th>
                <th style="text-align:center;"><strong>THIS QUANTITY</strong></th>
              </thead>
              <tbody>
                <?php
                $i=1;
        while($rs_rows=mysql_fetch_array($result_of_SQL_GET_POREF_FOR_ITEM))
                {
                  ?>
                  <tr <?=$bg?>>
                    <td align="center" style="padding-top:5px;">
                      <?=$i?>
                    </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['po_reference_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['item_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['unit_name'];?>
                    </font> </td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000"><?=$rs_rows['Total_Quantity'];?></font></td>
                    <td width="54%" align="center" style="padding-top:5px;"> <font color="#000000">
                      <input type="checkbox" name="check_list[]" value="<?=$rs_rows['po_refrence_id'];?>">
                    </font></td>
                    <td width="54%" align="center" style="padding-top:5px;">
                      <font color="#000000"><input type="text" name="txt[<?=$rs_rows['po_refrence_id'];?>]"></font>
                    </td>
                  </tr>
                  <?php
                  $i++;
                }
                ?>
                <tr class="text">
                  <td colspan="7"><div align="center">
                    <p>
                      <input type="hidden" name="req" value="<?=$req?>">
                      <input type="submit" name="save" value="Save" class="submit" tabindex="3"  >
                      <input type="reset" name="Reset" value="Cancel" class="submit" tabindex="4">
                      <?php
                      if(isset($_GET[msg])) echo "<font color=red>".$_GET[msg]."</font>";
                      // if(isset($messsag)) echo $messsag;

                      ?>
                    </p>
                  </div></td>
                </tr>
              </tbody></table>

this is the form where users issue the quantity to users, let suppose the requested quantity is 10, then it is upto admin to issue this 10 items from one po reference, or some quantity from po-laptop-hp-1 and some from po-dell-hp-1. 这是用户向用户发出数量的表格,假设请求的数量为10,则由管理员根据一个po参考发布这10个项目,或者从po-laptop-hp-1发出一些数量,从po发出一些数量-dell-hp-1。 I want to validate that before submitting it should be validate that quantity entered by user in text field for each row is less then the quantity in stock. 我想验证提交之前,应该验证用户在文本字段中为每一行输入的数量是否少于库存数量。 the sum of all text field quantity is not more than requested quantity. 所有文本字段数量的总和不超过要求的数量。 and else.... 还有...

i have write this code, but not working as i expected, 我已经编写了这段代码,但是没有按预期工作,

if(isset($_POST['save']))
{
  if ($_GET[add]==0)
  {
    if($_GET['req']=="") $abc= $_POST['req'];
    if($_POST['req']=="") $abc= $_GET['req'];
    echo $abc;
    $quantity_issued = $qty;
    foreach($_POST['check_list'] as $selected){
      foreach ( $_POST['txt'] as $key => $value )
      {
        echo 'Textbox #'.htmlentities($key).' has this value: ';
        echo htmlentities($value);
      }
      $SQL_Query_Get_Item_Quantity = mysql_query("SELECT * FROM stock WHERE po_refrence_id = '".$selected."'");
      if($SQL_Query_Get_Item_Quantity === FALSE){
        die(mysql_error());
      }
      else{
        $result_SQL_Query_Get_Item_Quantity = mysql_fetch_assoc($SQL_Query_Get_Item_Quantity);
        if($quantity_issued > $result_SQL_Query_Get_Item_Quantity['quantity'] && $result_SQL_Query_Get_Item_Quantity['quantity'] != 0){
          echo 'quantiy you want to issued is more than the quantity that this po refrence holds';
        }
        else{
          //echo $result_SQL_Query_Get_Item_Quantity['quantity']."</br>";
          echo 'quantiy you want to issued is less than the quantity that this po refrence holds';
        }
      }

    }

UPDATED: 更新:

I have done most of the work on this , the remaining is that i have to validate before save button pressed, is that the quantity entered in the text box is less than the quantity of the row/po reference. 我已经完成了大部分工作,剩下的就是我必须在按下保存按钮之前进行验证,即在文本框中输入的数量小于行/行引用的数量。

you can do this by using jquery validate plugin. 您可以通过使用jQuery Validate插件来做到这一点。 you need to call remote method of jquery validate plugin that works same as ajax. 您需要调用与ajax相同的jquery validate插件的远程方法。 so that you can check whether quantity entered by user in text field is less then the quantity in stock or not. 这样您就可以检查用户在文本字段中输入的数量是否少于库存数量。

Jquery validate plugin - remote method jQuery validate插件-远程方法

 $( "#myform" ).validate({
  rules: {
    email: {
      required: true,
      email: true,
      remote: "check-email.php"
    }
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM