How can I improve this code using object oriented programming?

Is this far from what you think of object oriented PHP, or can I improve it by adding HTML to the class? How can i do this? Note: the code below uses QuickForm on PEAR. Thanks in advance.

  <?php
    //MySQL class
    require_once('database/class.mysql.php');

    //Session class
    require_once('session/class.session.php');

    //SignUp class
    require_once('access/class.signup.php');

    //QuickForm class
    require_once('HTML/QuickForm.php');

    //PHPMailer class
    require_once('thirdparty/phpmailer/class.phpmailer.php');

    //Instantiate the MySQL class
    require_once('database/dbconnect.php');
    $db = &new MySQL($host, $dbUser, $dbPass, $dbName);

    //Instantiate the Session class
    $session = new Session;

     ?>

    <html>
        <head>
            <title>Test page</title>
        </head>
        <body>
            <?php
                //Instantiate Quickform
                $form = new HTML_QuickForm('regForm', 'POST');

                ///Header
                $form->addElement('header', null, 'Quickform tutorial example!');

                //First name
                $form->addElement('text', 'fname', 'First name:', array('size' => 30));
                $form->addRule('fname', 'Please enter your first name', 'required', null, 'client');

                //Last name
                $form->addElement('text', 'lname', 'Last name', array('size' => 30));
                $form->addRule('lname', 'Please enter your last name', 'required', null, 'client');

                //Password
                $form->addElement('password', 'pass', 'Password: ', array('size' => 30));

                //Gender
                $form->addElement('radio', 'sex', 'Gender: ', 'Male', 'male');
                $form->addElement('radio', 'sex', '', 'Female', 'female');

                //County
                $form->addElement('select', 'county', 'County:', array(
                    '0' => 'Select',
                    '1' => 'Louth',
                    '2' => 'Meath'
                ));

                //Date of Birth
                $form->addElement('date', 'dob', 'Date of Birth:', array('format' => 'dMY', 'minYear' => 1950, 'maxYear' => date('Y')));

                //Submit
                $form->addElement('submit', null, 'Submit');

                //Try to validate the form
                if ($form->validate()) {
                    echo 'Hello';
                }

                //Output the form
                $form->display();
            ?>
        </body>
    </html>
+3
source share
3 answers

Personally, I would not recommend using any HTML element generation class for your page assemblies, especially if it also includes dynamically generated javascript.

You could say, "Dude: what's the difference if it all ends up like HTML?"

, , , . , , a, , , , , . , , canvas. HTML- , br , . , CSS , , , , , .

, PHP , HTML , , - , - HTML, , PHP . , -, , , a) HTML- - ; ) HTML Javascript . PHP HTML/Javascript .

, PHP -, , , , , , HTML.

. , Templating , , - PHP.

+2

, PHP, Smarty. HTML PHP. , , , .. .

Smarty, , . Smarty, assign(), , display() HTML.

+2

- - , MVC, ( PHP) Symfony CakePHP.

- , , - .

+1

Source: https://habr.com/ru/post/1771605/


All Articles