DemoRegister::__construct PHP 메소드

__construct() 공개 메소드

Main method
public __construct ( )
    public function __construct()
    {
        // Validates the form input submitted, before writing to database
        if ($_POST) {
            $firstName = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING);
            $lastName = filter_input(INPUT_POST, 'lastname', FILTER_SANITIZE_STRING);
            $mail = filter_input(INPUT_POST, 'mail', FILTER_VALIDATE_EMAIL);
            // Performing validation
            if (empty($firstName) || empty($lastName)) {
                $error = 'Enter your name and last name';
            } else {
                if (isset($_POST['mail']) && !empty($_POST['mail']) && $mail == FALSE) {
                    $error = 'Enter a valid email address';
                }
            }
            // Displays a message in case of errors
            if (isset($error)) {
                self::$message = '<i style="color: #f50;">ERROR: ' . $error . '</i><br /><br />';
            } else {
                // SQL insertion in JSON format
                $json = '
                insert : [
                    {
                        table: "users" ,
                        values: { firstname: "' . $firstName . '", lastname: "' . $lastName . '", mail: "' . $mail . '"  }
                    }
                ]
                ';
                // Performs the new record and store the result
                list($total) = PDO4You::execute($json);
                // Displays a success message
                self::$message = 'Register #' . $total . ' added successfully!!<br /><br />';
            }
        }
        // Capture records of all registered users
        self::$hasRecords = PDO4You::select('SELECT * FROM users ORDER BY id DESC');
    }