Jump to content

[SOLVED] repeated code to a function


jimbo_3000

Recommended Posts

i am working with this code and i am trying to separate one section so i can just call it over and over but it is not working.  I tried putting the page by itself but it won't work when i call it.  What is the proper way of calling this function?

 

<?php

require_once('requires.php');
require_once('PhotoShareBase.php');


class CreateAccountPage extends PhotoShareBase
{
    public function __construct()
    {
        parent::__construct();
    }


    public function title()
    {
        return 'Create Account';
    }


    public function inlineStyle()
    {
        $style = <<<EOSTYLE
    label
    {
        margin-top: 0.5em;
        display: block;
        font-family: Arial, Helvetica;
        font-size: 10pt;
        color:  #444;
    }

EOSTYLE;
        return parent::inlineStyle() . $style;
    }

    protected function generateBodyContents()
    {
        parent::generateBodyContents();

        if (User::amILoggedIn())
        {
            echo 'Sorry, you can\'t be logged in when viewing this page';
            return;
        }

        echo <<<EOCONTENTS
<h3>Create a New User Account</h3>
  <form method='post' action='SubmitAccountData.php' name='create_user_form'>
     <div>
       <label>User Name:</label>
       <input type='text' name='user_name' size='30'>
     </div>
     <div>
       <label>Full Name:</label>
       <input type='text' name='full_name' size='30'>
     </div>
     <div>
       <label>Password:</label>
       <input type='password' name='password1' size='20'>
     </div>
     <div>
       <label>Password (confirm):</label>
       <input type='password' name='password2' size='20'>
     </div>
     <div>
       <label>Email Address:</label>
       <input type='text' name='email_address' size='30'>
     </div>
     <div>
       <label>User Bio:</label>
       <textarea name='user_bio' rows='10' cols='40'></textarea>
     </div>
     <p><input type='submit' value='Create User'></p>
  </form>
            
EOCONTENTS;
    }

}



$page = new CreateAccountPage();
$page->processRequest();



?>

 

this is the code that  is repeating i want to call it separately i tried a few things and it did no work.  It is mainly css but I still wanna be able to call it.

  public function inlineStyle()
    {
        $style = <<<EOSTYLE
    label
    {
        margin-top: 0.5em;
        display: block;
        font-family: Arial, Helvetica;
        font-size: 10pt;
        color:  #444;
    }

EOSTYLE;
        return parent::inlineStyle() . $style;
    }


Link to comment
Share on other sites

You can call methods without instantiating a class by prefixing the method with static (eg. static public function x()) and envoke the method by ClassName::methodName().

 

That said, you really should look into object oriented programming techniques and the paradigms associated with them as this code kind of feels like you're just programming in classes as if it was procedural programming.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.