Simple Registration Page Code Using Lua Script

Hello! Here is a simple code for a register page using Lua scripting. You are free to style the HTML codes however you want.
The code can be a little challenging to understand at first, but feel free to ask if you don’t understand any part.
Also see: Simple login page code using Lua scriptingHow to use it:

  1. Log in to the Wapka Dashboard (;
  2. Select your website from the “Your services” list;
  3. Now create a new page called “register” (Basic Function > New Page) – you can skip this step if you already have a register page and want to use it.
  4. Now open the register page we created and go to Advanced function > Script, and finally paste the following Lua code into the textarea:


-- Checks if a continue URL has been defined. If not, it is defined as the Home page
continue = req.get.continue or "/"

-- Check if the user is already logged in. If yes, redirect to continue URL
if (env.userid ~= 0) then 

-- Checks if the register form has been submitted
if (req.method == "POST" and then

    error_message = nil -- Starts error message as null

    email    =    -- Gets the email from the POST request
    username = -- Gets the username from the POST request
    password = -- Gets the password from the POST request
    fullname = -- Gets the full name as extra data to define a profile variable

    -- Checking whether the fields have been filled in
    if (email    == "" and
        username == "" and
        password == "" and
        fullname == "") then
        error_message = "You must enter all the fields."

    elseif (email    == "") then
        error_message = "You must enter your email."

    elseif (username == "") then
        error_message = "You must enter your username."

    elseif (username == "") then
        error_message = "You must enter your password."

    elseif (fullname == "") then
        error_message = "You must enter your full name."

    -- Continuing if all fields have been filled in
        -- Sets the parameters for the API register method
        local param = {
            email        = email,
            username     = username,
            password     = password,
            var_fullname = fullname -- Sets the full name as a custom variable!
        local is_ok, register, info, error_register = api.user_create(param)

        -- Checks whether the registration was successful
        if (is_ok) then

        else -- An error occurred while trying to register
            error_message = error_register -- Defines the error message as the one received in the register method

    -- Checks if any errors occurred and sets an error message div to display on the page
    if (error_message) then
        html_error = [=[<div class="error-message">%s</div>]=]
        error_message = string.format(html_error, error_message)

local html_code = [=[
<h2>Register an account</h2>
%s <!-- This is where the error message will be -->

<form method="post">

<div class="input">
<label for="email">Email:</label><br>
<input type="email" name="email" value="%s" placeholder="Email" id="email">

<div class="input">
<label for="username">Username:</label><br>
<input type="text" name="username" value="%s" placeholder="Username" id="username">

<div class="input">
<label for="password">Password:</label><br>
<input type="password" name="password" value="%s" placeholder="Password" id="password">

<div class="input">
<label for="fullname">Fullname:</label><br>
<input type="text" name="fullname" value="%s" placeholder="Full name" id="fullname">

<div class="input-button">
<input type="submit" name="process_register" value="Register" class="input-button">


<div class="register-message">
Already have an account? <a href="/login">Login</a>

print(string.format(html_code, error_message or "", email or "", username or "", password or "", fullname or ""))
Last edited by francisco on Sun Feb 18, 2024 4:09 am, edited 1 time in total.