Home > PHP Framework > ThinkPHP > body text

How thinkphp outputs registration success information on the front end

PHPz
Release: 2023-06-03 13:57:48
forward
1219 people have browsed it

Below we will take a simple registration page as an example to explain. We need to create a form first and place it in the register.html page. The following is the code of the form:

<form action="{:url(&#39;User/register&#39;)}" method="post">
    <label for="username">用户名</label>
    <input type="text" id="username" name="username" /><br/>

    <label for="password">密码</label>
    <input type="password" id="password" name="password" /><br/>

    <label for="email">邮箱</label>
    <input type="email" id="email" name="email" /><br/>

    <button type="submit" name="submit">注册</button>
</form>
Copy after login

In the form, we should notice {:url('User/register')} in the action attribute, which tells the system that after the user clicks the "Register" button, Submit the form data to the background and use the register() method for processing.

Next, we need to write the registration logic in the User controller. The code is as follows:

namespace app\index\controller;

use think\Controller;

class User extends Controller
{
    public function register()
    {
        $data = input(&#39;post.&#39;);
        // 完成注册逻辑
        
        $this->success(&#39;注册成功&#39;, &#39;User/login&#39;);
    }
}
Copy after login

In the register() method of the User controller, we first get the page through POST The parameters passed by the method. We can then run the complete registration process here, including verifying user information, writing to the database, etc. Finally, after we successfully register, we can output information to the front-end page through thinkphp's built-in success method.

Normally, the success method is used to jump to the page after performing a successful operation. Therefore, we will jump to the login page and let the user proceed to the next step.

The above is the detailed content of How thinkphp outputs registration success information on the front end. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!