Home  >  Article  >  PHP Framework  >  How thinkphp outputs registration success information on the front end

How thinkphp outputs registration success information on the front end

PHPz
PHPzforward
2023-06-03 13:57:481190browse

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>

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;);
    }
}

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete