How to grab data from post to a class

爱⌒轻易说出口 提交于 2019-11-30 22:29:01

Hello I think you need some tutorials on OPP first

You tube

Presentation

Other Links

Example of what you want

class RegisterUser {
    private $firstName;
    private $lastName;
    private $emailAddress;

    function __construct() {
        $this->firstName = isset($_POST['first_name']) ? $_POST['first_name'] : null;
        $this->lastName = isset($_POST['last_name']) ? $_POST['last_name'] : null;
        $this->emailAddress = isset($_POST['email_address']) ? $_POST['email_address'] : null;
    }

    function start() {
        if (empty($this->firstName) || empty($this->lastName) || empty($this->emailAddress)) {
            throw new Exception("Empty Post not allowed");
        }

        else
        {
            // Do some stuiff
            echo " Registration Done";
        }
    }
}

$register = new RegisterUser();
if(!empty($_POST))
{
    $register->start();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!