首页 > 解决方案 > post isset($_POST['next'] 在提交/刷新页面后没有设置。需要按两次才能设置如何解决?

问题描述

<script>
function refreshPage()
{
  document.forms[0].submit();
}    
</script>

<?php
       
 foreach($values as $value)
  {
  ?>
   <input type = "checkbox" name = "food[]" value = "<?php echo($value['dinner']);?>"  
     <?php if(isset($_POST['food'])) echo "checked='checked'"; ?> > // note this is still part of 
      input

  <?php 
       } 
    ?>


<button name = "pass" onClick = "refreshPage()">refresh</button>

<?php 

     if(isset($_POST['pass'])
    {    
        // do a lot more stuff but I have this for temp info
        echo("hello");
        // I am printing all the check box values in here I do not
        // have the code for it yet but I think ik how to do it
        // but since i do not have code for it now it is just empty
    }
?>

嗨所以每次我点击按钮刷新。isset($_POST['pass']) 不起作用。我必须单击它一秒钟才能设置它,然后打印你好和检查项目表部分。

我想要它,这样如果你点击它一次它就会打印你好。不是两次。如何修复我的代码?仅供参考,我知道你可以做 isset($_POST['food']) 让它工作。但这会破坏我代码的其他部分。

在我按下一次刷新按钮后,我需要按钮将 isset($_POST['pass']) 设置为 True(单击一次后)。

标签: phphtml

解决方案


推荐阅读