How to grab data from post to a class

前端 未结 1 399
悲哀的现实
悲哀的现实 2021-01-03 00:15

If I have a form such as (not all the code just one field and my input):

相关标签:
1条回答
  • 2021-01-03 00:42

    Hello I think you need some tutorials on OPP first

    You tube

    • http://www.youtube.com/watch?gl=NG&feature=related&hl=en-GB&v=_JEEQ-OPVAY

    Presentation

    • http://www.slideshare.net/mgirouard/a-gentle-introduction-to-object-oriented-php

    Other Links

    • http://buildinternet.com/2009/07/an-introduction-to-object-oriented-php-part-1/

    • http://blog.teamtreehouse.com/getting-started-with-oop-php5

    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();
    }
    
    0 讨论(0)
提交回复
热议问题