如何根据 PHP 的结果在加载时自动单击按钮 'not submit'
How to click a button 'not submit' automatically on load depending on a result from PHP
,我作为开发人员在网站上工作,使用 PHP ,
我现在拥有的是一个弹出式评论表单,当用户按下按钮时出现,
问题是我正在使用 PHP 验证它,当您按下提交时,如您所知,验证发生在服务器端,当它再次加载页面时,您会发现表单消失了,并且您必须再次按下该按钮才能看到验证结果
喜欢:"please enter a valid email.."、
如果 isset($_POST) 或类似的东西,我有什么办法可以自动按下那个按钮吗?
如果可以的话我可以提供网址link,需要的话告诉我
提前致谢
你可以有类似的东西
<?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()">
...
正如 War10ck 在评论中指出的那样,如果你打算使用这种方法,你还应该将 body onload="onLoad()"
标记包装在 if
语句中,这样如果弹出窗口不应该显示,并且由于 onLoad
函数未包含在 HTML 中,您不会在 Javascript.
中得到未定义的函数错误
另一种解决方案是首先不隐藏表单,例如:
<?php
$class = "hidden";
if (isset($_POST)...) {
$class = ""; // make the form not hidden if $_POST...
}
?>
<div id="form" class="<?php echo $class; ?>"> ...
哪里
.hidden {
display:none;
}
,我作为开发人员在网站上工作,使用 PHP ,
我现在拥有的是一个弹出式评论表单,当用户按下按钮时出现,
问题是我正在使用 PHP 验证它,当您按下提交时,如您所知,验证发生在服务器端,当它再次加载页面时,您会发现表单消失了,并且您必须再次按下该按钮才能看到验证结果 喜欢:"please enter a valid email.."、
如果 isset($_POST) 或类似的东西,我有什么办法可以自动按下那个按钮吗?
如果可以的话我可以提供网址link,需要的话告诉我
提前致谢
你可以有类似的东西
<?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()">
...
正如 War10ck 在评论中指出的那样,如果你打算使用这种方法,你还应该将 body onload="onLoad()"
标记包装在 if
语句中,这样如果弹出窗口不应该显示,并且由于 onLoad
函数未包含在 HTML 中,您不会在 Javascript.
另一种解决方案是首先不隐藏表单,例如:
<?php
$class = "hidden";
if (isset($_POST)...) {
$class = ""; // make the form not hidden if $_POST...
}
?>
<div id="form" class="<?php echo $class; ?>"> ...
哪里
.hidden {
display:none;
}