dongxiaofa6359 2015-08-11 20:34
浏览 96
已采纳

如何在加载时自动点击“不提交”按钮,具体取决于PHP的结果[关闭]

,I'm working on a website as a developer using PHP ,

what I have now is a pop up review form , which appears when the user press a button,

the problem is I'm validating it using PHP and when you press on the submit the validation occurs server side as you know and when it loads the page again you will find the form is gone , and you have to press that button again to see the result of the validation like: "please enter a valid email..",

is there any way I could press that button automatically if isset($_POST) or something similar ?

I can provide the website link if it is allowed , just tell me if you need it.

thanks in advance

  • 写回答

1条回答 默认 最新

  • dongzaizai2015 2015-08-11 20:39
    关注

    You could have something like

    <?php if (isset($_POST)...){ ?>
    
        <script>
            // here you could call the Javascript function which is called when the button is clicked
           function onLoad() {
               yourFunction();
           }
        </script>
    
    <?php } ?>
    
    <body onload="onLoad()">
    ...
    

    As War10ck pointed out in the comments, if you're going to use this approach, you should also wrap the body onload="onLoad()" tag within the if statement so that if the pop up should not show, and because of that the onLoad function is not included in the HTML, you won't get an undefined function error in Javascript.

    Another solution would be to not hide the form in the first place i.e something like this:

    <?php
        $class = "hidden";
        if (isset($_POST)...) { 
            $class = ""; // make the form not hidden if $_POST...
        }
    ?>
    <div id="form" class="<?php echo $class; ?>"> ...
    

    where

    .hidden {
        display:none;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)