This article mainly introduces the detailed method of automatic form submission. Interested friends can refer to it. I hope it will be helpful to everyone.
When working on a project, for example, a B2B person jumps from the mall to the backend of the Seller Center. When he has both a member account and a seller, let him log in to the mall, and there is no need for the seller to log in. You can use the form form to log in automatically during the process.
Simple idea: you can log in as an ordinary member. If you log in successfully, you can save your login name, password, and user ID. For security, you can encrypt it with AES (detailed introduction in the previous article) and store it in cookies. On the page, you need to go to the seller center, where you can determine the cookie that was initially saved and whether it is a seller. If so, use the form to automatically log him in.
Case implemented on ecshop:
Create a lib_stm_form.php under includes:
class form{ public function hform($username,$password){ $str = '<body><form action="privilege.php" method="post" id="qqform" name="qqform" style="display:none"> ' ; $str .= '账号:<input type="text" name="username" value="' . $username . '" /><br />' ; $str .= '密码:<input type="text" name="password" value="' . $password . '" /><br />' ; $str .='<input type="hidden" name="act" value="signin" /></form></body>'; $str .= '<script>window.onload= function(){document.getElementById("qqform").submit();}</script>'; echo $str; exit; } } ?>
In the signin method of privilege.php, perform aes decryption and introduce lib_stm_form.php::
require_once(ROOT_PATH . 'includes/lib_smt_from.php'); $form = new form(); $username = $j_token['username']; $password =$j_token['password']; $a = $form->hform($username,$password); exit;
This is achieved. The form is automatically submitted for login. If you are a member or seller, you can log in once.
The above example explanation of form automatic submission is all the content shared by the editor. I hope it can give you a reference.
Related recommendations:
form Detailed explanation of form serialization (graphic tutorial)
Vue Dynamically generated formDetailed explanation of form cases
Detailed explanation of React Form component encapsulation steps
The above is the detailed content of Detailed explanation of how to implement automatic form submission. For more information, please follow other related articles on the PHP Chinese website!