Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 提交时形成if-then-Else/ifElse HTML_Php_Html_Forms - Fatal编程技术网

Php 提交时形成if-then-Else/ifElse HTML

Php 提交时形成if-then-Else/ifElse HTML,php,html,forms,Php,Html,Forms,我有一个表格,我需要以特定的方式行事。示例:用户将设备带回来:我不希望它显示在我的表单中。用户取出设备:我希望它生成到我的表单,他们输入一些信息,表单将信息发送到数据库。用户取出设备:它也生成所述表单,他不输入任何信息,表单在20秒后提交信息,信息在数据库中 我在做一个简单的页面刷新,把信息放到我的表格中,但那是把那天带进仓库的所有设备都拖走了。所以我把它注释掉了,然后我会被我的ajax页面卡住 然后我尝试创建一个新的php页面,该页面有301页面刷新,可以将页面恢复到我的索引页面,但是,我的表

我有一个表格,我需要以特定的方式行事。示例:用户将设备带回来:我不希望它显示在我的表单中。用户取出设备:我希望它生成到我的表单,他们输入一些信息,表单将信息发送到数据库。用户取出设备:它也生成所述表单,他不输入任何信息,表单在20秒后提交信息,信息在数据库中

我在做一个简单的页面刷新,把信息放到我的表格中,但那是把那天带进仓库的所有设备都拖走了。所以我把它注释掉了,然后我会被我的ajax页面卡住

然后我尝试创建一个新的php页面,该页面有301页面刷新,可以将页面恢复到我的索引页面,但是,我的表单工作不正常,所以我注释掉了自动提交,现在我的表单工作得很好。。。除非我不能满足最后一个要求,如果用户忘记输入设备信息,页面将提交数据

我想做一个if/then/else类型的页面提交。然而,我不知道如何在php或html中完成一个。到目前为止,我已经明白了这一点,但它不起作用,我知道我离某个地方很远

<!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>
           }

          ?>

//这是我的白日梦
除了通过codecademy,我对jQuery了解不多,对javascript的了解更少。我是一个数据库人员,被“骗”去构建一个高级表单/网页。所以我在编写代码时学习PHP、CSS、jQuery和HTML

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>

您不能将PHP与JavaScript混合使用,为什么要将超时设置为1000*30,这等于将超时设置为30000,也就是30秒。 然后,您可以使用输入字段中的“require”属性强制用户填写所需信息

<!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><?= $equipment['Amount']; ?></td>
                <td class="text-center">
                  <?php echo $equipment[‘quantity']; ?>
                </td>
                <td>
                  <input id="val1" type="text" name="val1”/>
                </td>
                <td>
                  <input id="val2" type="text" name="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">
    window.setTimeout(function(){
      var val1 = document.getElementById("val1").value,
          val2 = document.getElementById("val1").value;

      if ( ! val1 && ! val2 ) document.getElement('formSubmit').submit();
    },30000);
  </script>
</body>
</html>


请尝试这个新的解决方案。这将每30秒发送一次帖子,其中只包含包含文本的输入框

<!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>

使用者
3962仓库
装备
数量
瓦尔1
瓦尔2

如果这些卷曲的引号是你真实代码的一部分,那么你就失败了。另外,我们不知道您的HTML表单是什么样子的。检查错误和你的控制台。我得去喂马了。你再次看到这个
案例“完成”
。。。如果这是您的实际代码,它将阻塞您的代码。这应该理解为
大小写“完成”:
带有常规引号
而不是卷曲引号
'
。总共有两种不同的动物。你不能像那样混合使用PHP和JavaScript,加上@Fred ii-指出的你的引号,会扼杀代码。确保使用纯文本编辑器进行编码。为此,您需要使用AJAX使您的逻辑工作,为每个离散的PHP函数调用AJAX。上述评论已经指出了这一点。我也意识到你不能把它们结合起来。。我正在寻找这种类型的If/then语句。我从来没有说过我的代码是正确的,我请求帮助是因为我意识到我的代码不起作用,我在同一个问题上失去理智工作了3天多,而我知道必须有一种合乎逻辑的方式来完成这项任务。我要30秒的时间。你需要再读一遍这个问题,才能理解我在这里想要实现的目标。好吧,在这种情况下,我希望我的解决方案能把你带向正确的方向。看一下代码,看看它是否有效。我不想强迫他们添加信息。我希望他们有机会添加2个文本值,以指示他们想要这些零件的用途以及将它们带到何处。如果他们不这样做,我希望它在30秒后超时(一个人输入信息的永恒时间),然后将信息发送到数据库。我还想让它超越我的ajax页面,回到索引页面(表单所在的位置)。现在,如果两个textfiled为空,则表单将在30秒后提交。如果那是你要找的,请告诉我for@SheaPrice对,那是因为foreach语句中的所有输入都有相同的id。那么我们就接近解决方案了。现在的问题是,您有一个包含所有输入字段的forn,因此,当您提交表单时,它会提交所有输入值。您可以将表单包含在foreach中,并仅提交用户正在编辑的表单。这已完成!我花了一段时间才让这些东西与API交互,但这是应用程序开发人员的工作,而不是我的工作。谢谢你的帮助,桑尼!