douzhongjian0752 2016-02-05 14:57
浏览 46
已采纳

表格,如果那么Else / ifElse HTML提交

I have a form that I need to act in specific ways. Example: User brings equipment back: I don't want that to show up in my form. User takes equipment out: I want it to generate to my form, they enters some information, form sends information to database. User takes equipment out: it too generates said form, he doesn't enter any information, form submits information after 20 sec, information is in database.

I was doing a simple page refresh to get the information into my form but that was pulling all the equipment that had been brought into the warehouse that day. So I commented that out and then I would get stuck on my ajax page.

I then tried creating a new php page that had a 301 page refresh and that worked to get the page back to my index page, however, my form wasn't working properly and so I commented out the auto submit and now my form works great... except I can't fulfill this last requirement where the page will submit the data if the user forgets to put his equipment information in.

I'm looking to do an if/then/else type of page submission. However, I can't figure out how to do one purely in either php or html. This is what I have figured out so far but it doesn't work and I know I'm way off somewhere.

<!DOCTYPE html>
<html>
<body>

<!--This is the one that is currently commented out in my code
<script type="text/javascript">
 window.setTimeout(function() {
 window.location = 'index.php'},1000*2);
</script>
</body>
</html> -->

  //This is my pipe dream 
   <?php
   if (isset($_POST['action'])) {
        switch ($_POST['action']) {
                    case ‘DONE’:
                        document.getElement('formSubmit').submit();
                        break;
            }
              } else {
                 <script type="text/javascript">
                     window.setTimeout(function(){
                     document.getElement('formSubmit').submit();
                },1000*30);
                 </script>
           }

          ?>

I don't know that much about jQuery other than going through a codecademy, and I know even less javascript. I'm a database person that got "conned" into building an advanced form/webpage. So I'm learning PHP, CSS, jQuery and HTML as I code.

Index.php:

<!DOCTYPE html>
<html>
<head>
<meta name=“Warehouse 3962” content="width=device-width, initial-scale=1.0">
<link href="style.css" type="text/css" rel="stylesheet">
<script type="text/javascript">
<!—window.setTimeout(function(){
              document.getElement(‘formSubmit').submit();
              },1000*30); —>
</script>
</head>
<body>
<section class="w">
    <div class="row">
        <div class="small columns">
            <img src="logo.png" />
            <h3 class="green">Users</h3>
        </div>

        <h6>Warehouse 3962</h6>
    </div>

    <div class="row">
        <div class="small columns">
            <form action="ajax.php" method="post" id="formSubmit">
                <table id="equipment-table">
                    <thead>
                        <tr>
                            <th>Equipment</th>
                            <th>Amount</th>
                            <th>Val1</th>
                            <th>Val2</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php foreach 
                        ($results['tags'] as $equipment) {
                            if ($equipment['category'] == "Part") { ?>

                                <tr>
                            <td><?= $equipment['Amount']; ?></td>
                <td class="text-center"><?= $equipment[‘quantity']; ?></td>
                                    <td><input type="text" name="val1" /></td>
                                    <td><input type="text" name="val2" /></td>
                                </tr>

                            <?php } // end if
                        } // end foreach ?>

                        <tr>
        <td colspan="4" style="text-align: right;"><input      type="submit" class="button" name="DONE" value="DONE" /></td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>
</section>
</body>
</html>
  • 写回答

2条回答 默认 最新

  • duanchanguo7603 2016-02-05 19:23
    关注

    Please try this new solution. This will send a post every 30 seconds containing only the input boxes containing text on them.

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="Warehouse 3962" content="width=device-width, initial-scale=1.0">
    <link href="style.css" type="text/css" rel="stylesheet">
    </head>
    <body>
      <section class="w">
        <div class="row">
          <div class="small columns">
            <img src="logo.png" />
            <h3 class="green">Users</h3>
          </div>
    
          <h6>Warehouse 3962</h6>
        </div>
    
        <div class="row">
          <div class="small columns">
            <form action="ajax.php" method="post" id="formSubmit">
              <table id="equipment-table">
                <thead>
                  <tr>
                    <th>Equipment</th>
                    <th>Amount</th>
                    <th>Val1</th>
                    <th>Val2</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  foreach ($results['tags'] as $equipment) :
                  if ($equipment['category'] === "Part") :
                  ?>
                  <tr>
                    <td>
                      <?php echo $equipment['Amount']; ?>
                    </td>
                    <td class="text-center">
                      <?php echo $equipment['quantity']; ?>
                    </td>
                    <td>
                      <input id="<?php echo $equipment['number'];?>-val1" type="text" name="<?php echo $equipment['number'];?>-val1"/>
                    </td>
                    <td>
                      <input id="<?php echo $equipment['number'];?>-val2" type="text" name="<?php echo $equipment['number'];?>-val2"/>
                    </td>
                  </tr>
                  <?php
                    endif;
                    endforeach;
                   ?>
                  <tr>
                    <td colspan="4" style="text-align: right;">
                      <input type="submit" class="button" name="DONE" value="DONE" />
                    </td>
                  </tr>
                </tbody>
              </table>
            </form>
          </div>
        </div>
      </section>
      <script type="text/javascript">
        function sendData() {
          var inputs = document.getElementById('equipment-table').getElementsByTagName('input'),
              data = [],
              name, val1, val2;
    
          for (var i = 0; i < inputs.length; i++) {
            if ( inputs[i].type === 'submit') {
              continue;
            }
    
            if ( inputs[i].value ) {
              name = inputs[i].name.split('-val');
              val1 = inputs[i].name.split('val1');
    
              if (val1.length > 1) {
                data.push({name: name[0], val1: inputs[i].value});
              }
              else {
                data.push({name: name[0], val2: inputs[i].value});
              }
            }
          }
    
          window.setTimeout(function() {
            sendData();
          },30000);
        }
    
        sendData();
      </script>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch