我正在尝试使用 javascript 自动提交登录表单,但它无法启动 session 并重定向到同一页面,但是当我尝试在没有 javascript 的情况下提交相同的表单时,它可以正常工作。 我需要自动提交表格。有什么建议吗?
<?php include('_header.php'); ?>
<form id="my_form" method="post" action="index.php" name="loginform">
<label for="user_name"><?php echo WORDING_USERNAME; ?></label>
<input id="user_name" type="text" value="something" name="user_name" required />
<label for="user_password"><?php echo WORDING_PASSWORD; ?></label>
<input id="user_password" type="hidden" value="something1" name="user_password" />
<input type="checkbox" id="user_rememberme" name="user_rememberme" value="1" />
<label for="user_rememberme"><?php echo WORDING_REMEMBER_ME; ?></label>
<input type="submit" name="login" value="<?php echo WORDING_LOGIN; ?>" />
</form>
<script type="text/javascript">
function submitForm() {
document.getElementById('my_form').submit();
}
window.onload = submitForm;
</script>
<a href="register.php"><?php echo WORDING_REGISTER_NEW_ACCOUNT; ?></a>
<a href="password_reset.php"><?php echo WORDING_FORGOT_MY_PASSWORD; ?></a>
<?php include('_footer.php'); ?>
最佳答案
如果您想在页面访问时自动提交表单,只需将此代码放在表单后面即可:
<script>
document.getElementById('my_form').submit();
</script>
关于javascript - 自动提交登录表单并启动 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141454/