Home  >  Article  >  Backend Development  >  Detailed explanation of how to implement automatic form submission

Detailed explanation of how to implement automatic form submission

墨辰丷
墨辰丷Original
2018-05-19 14:26:272643browse

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 = &#39;<body><form action="privilege.php" method="post" id="qqform" name="qqform" style="display:none"> &#39; ;
    $str .= &#39;账号:<input type="text" name="username" value="&#39; . $username . &#39;" /><br />&#39; ;
    $str .= &#39;密码:<input type="text" name="password" value="&#39; . $password . &#39;" /><br />&#39; ;
    $str .=&#39;<input type="hidden" name="act" value="signin" /></form></body>&#39;;
    $str .= &#39;<script>window.onload= function(){document.getElementById("qqform").submit();}</script>&#39;;
    echo $str; exit;
  }
}
?>

In the signin method of privilege.php, perform aes decryption and introduce lib_stm_form.php::

require_once(ROOT_PATH . &#39;includes/lib_smt_from.php&#39;);
$form   = new form();
$username = $j_token[&#39;username&#39;];
$password   =$j_token[&#39;password&#39;];
$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn