SitePoint Sponsor

User Tag List

Results 1 to 23 of 23
  1. #1
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where do you put PHP

    Sounds like a dumb question, right?!

    Well not really, to me at least!

    If the code below represented "TEST.php", where could I put the PHP code and not cause issues or break any coding conventions?!


    ********************************************************
    Could I put my PHP here??

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">


    Could I put my PHP here??

    <head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <!--<link rel="stylesheet" type="text/css" href="tabs.css" />-->
    <style type="text/css">



    </style>
    </head>

    Could I put my PHP here??

    <body>

    Certainly I could put my PHP here?!

    </body>

    Could I put my PHP here??

    </html>

    Could I put my PHP here??
    ********************************************************

    Thanks,


    Amy

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're going to be putting code which performs logic in the same file as the code which outputs html, you probably want the bulk of your php code at the top of the file. During the course of processing the logic, you might find out you don't actually want to putput any html(maybe, you wanna redirect or something).

    You might find it feels better separated if you make a separate php file which kind of acts as a template. This file contains html and just basic php code such as <?php echo $foo; ?> as well as some minimal loops and control statements neccesary to create the proper html markup. Then you just use include 'myTemplate.php';

    More elaborate systems use multiple layers of separation before getting to the html output/template stage.

    But, it's common to kinda mix the php in with the html. It's not generally viewed as a great practice, but don't over engineer just for the sake of it. You might appreciate the benefits of separation more after you experience some of the drawbacks of mixing it all up

  3. #3
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are going to put PHP logic in the same file as HTML (which is not a good practice, you should separate business logic and presentational logic), do it like this:

    PHP Code:
    <?php

    // ...

    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    Notice that I have put the doctype tag right after the ending ?>. That is because if the doctype tag is not the first line in the outputted HTML, Internet Explorer will go into so called "QuirksMode" which can cause some problems.

  4. #4
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by crmalibu View Post
    You might appreciate the benefits of separation more after you experience some of the drawbacks of mixing it all up
    Based on the emergency state of my life/project, that might just happen!

    Thanks,


    Amy

  5. #5
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the best way to layout things to handle a form?

    (Let me stress that I have to have my Seminar Registration system done this week, so true eloquence is not the goal. When Amy 2.0 comes out, then I'll "sexy" things up. I just want relatively sound, and easy to follow code!!)

    The book I'm following seems to start off the PHP file with PHP like this...

    Code:
    <?php # Script 16.6 - register.php
    // This is the registration page for the site.
    
    if (isset($_POST['submitted'])) { 
    	// Handle the form.
    
    }
    ?>
    	
    <h1>Register</h1>
    <form action="register.php" method="post">
    	<fieldset>
    
    </form>
    What are your thoughts on this?

    I guess to me, it seems somewhat confusing since logically you FIRST display the form, THEN you handle the form.

    So to me - since I'm anal-retentive - I would do this...

    Code:
    <html>
    
    
    </html>
    
    <?php
    
    
    ?>
    But what do I know?!


    Amy

  6. #6
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code is executing from top to bottom. So if you do it like that then the form will be printed before it's been handled by PHP.

    What if you want to display some error or success message on top of the form? You have already printed the form before you validated it so you can't do that.

  7. #7
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also if I understand it correctly you are trying to make a registration page. After a successful registration you will probably want to redirect to some other page, it's best to that before outputting the HTML.

  8. #8
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <?php

    $field1 
    '';

    if (isset(
    $_POST['submit_button'])) {
        
    $field1 $_POST['field1'];
    }

    ?>

    <form action="" method="post">
    <input type="text" name="field1" value="<?php echo (isset($field1)) ? $field1 ''?>" />
    <input type="submit" name="submit_button" value="Submit" />
    </form>
    PHP Code:

    <form action="" method="post">
    <input type="text" name="field1" value="<?php echo (isset($field1)) ? $field1 ''?>" />
    <input type="submit" name="submit_button" value="Submit" />
    </form>

    <?php

    $field1 
    '';

    if (isset(
    $_POST['submit_button'])) {
        
    $field1 $_POST['field1'];
    }

    ?>
    Try executing these two pages (write something into the text field) and notice the difference.

  9. #9
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    Also if I understand it correctly you are trying to make a registration page. After a successful registration you will probably want to redirect to some other page, it's best to that before outputting the HTML.
    Let me see if I follow you...

    So you put the PHP first and then the HTML.

    First time the PHP is ignored and the HTML Registration Form is displayed.

    Second time (i.e. upon "Submit") the PHP is run...

    If there are errors, then the HTML Registration Form is displayed again but with errors.

    And if everything was okay, then you use an Exit( ); in my PHP and the HTML Registration Form is not displayed again?

    Is that how I should be thinking?

    Thank you Richard. (BTW, I love your avatar!!)


    Amy

  10. #10
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amy.damnit View Post
    Let me see if I follow you...

    So you put the PHP first and then the HTML.

    First time the PHP is ignored and the HTML Registration Form is displayed.

    Second time (i.e. upon "Submit") the PHP is run...

    If there are errors, then the HTML Registration Form is displayed again but with errors.

    And if everything was okay, then you use an Exit( ); in my PHP and the HTML Registration Form is not displayed again?

    Is that how I should be thinking?

    Thank you Richard. (BTW, I love your avatar!!)


    Amy
    Exactly.

    But I would not use exit(). Just use if() to show the register form, something like:

    PHP Code:
    <?php if(true === $showRegistrationForm): ?>
    <form action="" method="post">
    ...
    </form>
    <?php endif; ?>

  11. #11
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    Exactly.

    But I would not use exit(). Just use if() to show the register form, something like:

    PHP Code:
    <?php if(true === $showRegistrationForm): ?>
    <form action="" method="post">
    ...
    </form>
    <?php endif; ?>
    Sorry, SitePoint is on the fritz today. I made a post and then your posts which was before mine didn't show up until a=AFTER I made my post?!

    So, you are saying to encapsulate all of my HTML inside PHP tags so that I can control when it is displayed?


    Amy

  12. #12
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amy.damnit View Post
    Sorry, SitePoint is on the fritz today. I made a post and then your posts which was before mine didn't show up until a=AFTER I made my post?!

    So, you are saying to encapsulate all of my HTML inside PHP tags so that I can control when it is displayed?


    Amy
    Basically yes, that's how it is done.

  13. #13
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    Basically yes, that's how it is done.
    Richard, I'm sorry but I'm getting more confused. (Must be the stress of my deadline...)

    Let me back up...

    The book I read took this apporach with most examples...

    header.html
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <head>
      <title></title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <!--<link rel="stylesheet" type="text/css" href="tabs.css" />-->
      <style type="text/css">
      </style>
    </head>
    <body>
    
    <!-- Header type HTML...  ->
    
    
    <!-- Start of page-specific content. -->

    index.php
    Code:
    <?php
    
    include{'includes/header.html');
    
    ?>
    
    <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec tempus massa vitae dolor ultrices laoreet. Vestibulum quam libero, iaculis a ultrices in, vulputate non dolor. Donec sodales dapibus diam, egestas convallis turpis pharetra a.
    </p>
    
    <?php
    
    include{'includes/footer.html');
    
    ?>

    footer.html
    Code:
    <!-- End of page-specific content. -->
    </body>
    </html>

    For the kinds of things in the book that seemed okay, but I'm not sure if such a coding approach applies to my site?!

    The way the author laid things out, it reads like a newsletter where you always assume there is some Page Header followed by variable content followed by a Footer.

    But my Seminar Registration forms don't have "Headers" and "Footers" in an HTML or Page sense.

    Each form is unique, and the presentation (HTML) and logic (PHP) are intermingled in my mind?!

    So I'm probably making a mountain out of a mole hill, but I'm just getting off to a rocky start coding my completed HTML pages with PHP logic.

    Does that make sense?

    Can you (or anyone) shed some light on how I should approach things so I don't have spaghetti code?? AND so it makes sense to me?!

    Thanks,


    Amy

  14. #14
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can approach the things like the author of the book you are reading. Put only beginning of HTML markup into header.html (doctype, head section etc) because that will be the same for all pages. Also the footer will be the same for all pages. So basically the only thing that will change will be the content part. You will put there your registration forms.

  15. #15
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    You can approach the things like the author of the book you are reading. Put only beginning of HTML markup into header.html (doctype, head section etc) because that will be the same for all pages. Also the footer will be the same for all pages. So basically the only thing that will change will be the content part. You will put there your registration forms.
    So is that how you do it?

    Is that a more acceptable way, versus mixing things together?

    Or is separating the Presentation Layer from the Business layer more complicated than that?

    I was confused becuase the author was doing like websites where his Header.html had a physical header/banner in it and his Footer.html had a real footer with a copyright and other footer type info.

    On my forms, I have decided to not obfuscate the design by having VISUAL Headers and Footers per say.

    But it sounds like you are saying that my "Header" can just contain...

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <head>
      <title>Sign-In/Create Account</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <!--<link rel="stylesheet" type="text/css" href="tabs.css" />-->
      <style type="text/css">
    type stuff without necessarily having a visual "page header/heading", right?

    Is that the gist of what you are saying?


    Amy

  16. #16
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the header can just contain necessary markup like doctype, head, meta tags etc...

    So is that how you do it?

    Is that a more acceptable way, versus mixing things together?

    Or is separating the Presentation Layer from the Business layer more complicated than that?
    No I don't do it like that. I'm using MVC design pattern to separate business and presentational logic.

    But that is a little bit too complex for an absolute beginner so don't worry about that. Just do it like it's in the book.

  17. #17
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    Yes, the header can just contain necessary markup like doctype, head, meta tags etc...
    Problem is that won't really provide any value.

    No I don't do it like that. I'm using MVC design pattern to separate business and presentational logic.
    Yah, in the near future I'd like to re-write this using OOP and MVC.


    But that is a little bit too complex for an absolute beginner so don't worry about that. Just do it like it's in the book.
    A lot bit!


    Here is an example of one of my files. (Each separate web page has a fairly similar structure.)

    Code:
    <?php
      $email = $_POST['email'];
      $new_customer = $_POST['new_cust'];
      $password = $_POST['password'];
    
      // ADD MORE CODE HERE...
    
    ?>
    
    
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <head>
      <title>Sign-In/Create Account</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <!--<link rel="stylesheet" type="text/css" href="tabs.css" />-->
      <style type="text/css">
        /* DEV: Identify Element Edges */
        /*
        * {
            border: 1px dotted #FF0000;
        }
        */
    
    
        html,
        body {
          margin: 0px;
          padding: 0px;
          background-color: #FFFFFF;            /* White */
          font-family: Arial, Helvetica, sans-serif;
          font-size: 1em;   /*0.8em/1.8em*/
          color: #000000;                       /* Black */
        }
    
        a {
          outline: none;
          font-size: 0.8em;
        }
    
        #wrapper {
          overflow: hidden;     /* Helps to "contain" floated children. */
          width: 850px;
          margin: 70px Auto;
          padding: 50px;
          border: 1px solid #808080;
        }
    
        #header {
          float: left;
          width: 100%;
          margin: 0em 0em 1em 0em;
          padding: 0em;
          font-size: 1.4em;
          font-weight: bold;
        }
    
        #content {
          clear: both;
        }
    
        #content h2 {
          margin: 0px 0px -2px 0px;
          font-size: 1em;
          color: #FF6600;
        }
    
        p {
          margin: 0 0 1em;
          font-size: 0.8em;
        }
    
        /* PAGE CONTENT STYLES */
        form {
          padding: 0px 0px 0px 200px;
        }
    
        ol {
          margin: 0px;
          padding: 0px 0px 30px 20px;
          list-style-type: lower-alpha;
        }
    
        .step {
          margin: 14px 0px 0px 0px;
        }
    
        label {
          display: block;
          padding: 0px 0px 5px 0px;
          font-weight: bold;
        }
    
        input {
          display: block;
          font-size: 1em;
        }
    
        .cust_status label {
          display: inline;
          padding: 0px 0px 5px 0px;
          font-weight: normal;
        }
    
        .cust_status input {
          display: inline;
          font-size: 1em;
        }
    
        .proceed {
          margin: 14px 0px 20px 20px;
        }
    
    
      </style>
    </head>
    <body>
      <!--####################  HTML CODE  ####################-->
      <div id="wrapper">
        <!--####################  PAGE HEADER  ####################-->
        <div id="header">
          STEP 2: Sign-In/Create Account
        </div>
    
        <!--####################  PAGE CONTENT  ####################-->
        <div id="content">
          <h2>Registering is quick and easy...</h2>
    
          <!-- LOG-IN FORM -->
          <form action="104_CreateUser.xhtml" method="post">
            <ol>
              <!-- a.) E-MAIL ADDRESS -->
              <li class="step">
                <label for="email">Enter your e-mail address:</label>
                <input id="email" type="text" name="email" size="30" maxlength="80"
                       value="<?php if (isset($email)) {echo $email}; ?>" />
              </li>
    
              <!-- b.) CUSTOMER STATUS -->
              <li class="step">
                <label  for="radio">Choose a customer status:</label>
                <div class="cust_status" id="radio">
                  <div>
                    <input id="new_cust" type="radio" name="new_cust" value="TRUE" checked="checked"/>
                    <label for="new_cust">I'm a new customer</label>
                  </div>
                  <div>
                    <input id="ret_cust" type="radio" name="new_cust"  value="FALSE" />
                    <label for="ret_cust">I'm a returning customer</label>
                  </div>
                </div>
              </li>
    
              <!-- c.) PASSWORD -->
              <li class="step">
                <label for="password">Returning customers, what is your password?</label>
                <input id="password" type="text" name="password" size="20" maxlength="20" />
              </li>
            </ol>
    
            <!-- HIDDEN INPUT -->
            <input type="hidden" name="submitted" value="TRUE" />
    
            <!-- PROCEED BUTTON -->
            <input type="image" src="images/Proceed.jpg"
                   alt="Proceed" class="proceed" border="0" />
    
            <!-- FORGOT PASSWORD LINK -->
            <a href="#" class="proceed">Help, I Forget My Password?!</a>
          </form>
        </div>
      </div>
    </body>
    </html>
    Because each seperate web page in my registration process is disparate from the next, all of the XHTML and CSS for a given web page is specific to the given page.

    So there is no value - as I see it - to separate the XHTML and CSS from the PHP for this series of pages?!


    (The only thing I could recycle is maybe the first 3 lines of the HTML header which is not even worth noting.)

    If, like in the book I read, the web pages were like a newspaper where you see the same page heading for the [i]New York Times[i] and the same copyright and contact info in the footer, then the author's model makes more sense.

    Yah, in an ideal world, I could put all of my CCS in one file, but the reality is that I didn't have time to architect a global CSS style library.

    So, knowing this, can I just put my PHP first like you - or someone else - originally mentioned?

    And/or can I do that, but I need to WRAP all of my XHTML in PHP tags like this...

    Code:
    <?php
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
    <head>
      <title>Sign-In/Create Account</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <!--<link rel="stylesheet" type="text/css" href="tabs.css" />-->
      <style type="text/css">
    
      </style>
    </head>
    <body>
    
    </body>
    </html>
    
    ?>
    
    Thanks,


    Amy

  18. #18
    SitePoint Evangelist Waffles's Avatar
    Join Date
    Nov 2005
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one approach would be to create pages like so

    PHP Code:
    <html>
    <!-- 
    doc type etc etc being lazy-->
    <
    head>
    <!-- 
    css file -->
    <
    title>Bla bla</title>
    </
    head>

    <
    body
    save has header.php


    PHP Code:
    </body>
    </
    html
    save as footer.php

    (or .htm doesnt really matter)

    then say:

    index.php
    PHP Code:
    <?php include('header.php'); ?>
    <h1>My Site</h1>
    <?php 
    $show_form
    =true;
    if(isset(
    $_POST['submit']))
    {
     
    // process form

    $show_form=false;
    }

    if(
    $show_form) { ?>

    <form>
    <!-- form -->
    </form>
    <?php ?>
    <p> bla bla</p>
    <?php include('footer.php'); ?>
    one approach, certainly a basic one. mix of PHP and html, you can edit the majority of your page content in HTML and just use PHP to control bits where necessary. Wouldn't worry too much about file size as unless you are working with thousands of lines of code and loads of complex queries the overhead (or lack of) just isn't worth thinking about


    put all the CSS in to one css file and just access it as required. If your css is changing that drastically on a per-page-basis then you may want to rethink things, pages should share at least some common elements. I'd typically create a template and have a "mainContent" div which may change depending on the page content, but the nav/sidebar/footer/etc/etc all remains the same on the majority of the pages

  19. #19
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm too tired already (it's 00:30 here) so just few comments.

    You are doing something wrong when each page has completely different styles. I would guess there would be at least some common styling like text fields padding, border, font, color etc which would be consistent among all pages.

    But if it's really so different, just put all styles (for all forms) into one stylesheet and include it in the header. I rarely use more than 1 stylesheet (and if I do, each stylesheet is for a different module) and I've worked on some complex websites so I don't quite understand how it is difficult to put everything into 1 file.

    Just use different ids for each form and then in the styles use those ids to set different styles for each form.

    Also, don't wrap HTML markup in <?php ?>. That's incorrect and you will get a parse error. Put only PHP code inside <?php ?>. Like this:

    PHP Code:

    <?php

    // some PHP code here...

    ?>

    <!-- some HTML markup here... -->

    <?php

    // some other PHP code here...

    ?>

    <!-- more HTML markup here... -->

  20. #20
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by risoknop View Post
    I'm too tired already (it's 00:30 here) so just few comments.

    You are doing something wrong when each page has completely different styles. I would guess there would be at least some common styling like text fields padding, border, font, color etc which would be consistent among all pages.

    But if it's really so different, just put all styles (for all forms) into one stylesheet and include it in the header. I rarely use more than 1 stylesheet (and if I do, each stylesheet is for a different module) and I've worked on some complex websites so I don't quite understand how it is difficult to put everything into 1 file.
    Because I coded one page at a time to get the desired look I wanted.

    And as I coded each seperate page, I made styles - often modifying built in tags - as I went.

    So on Page 1, maybe I had...

    p {
    margin: 0px;
    padding: 0px;
    }

    #button {
    float:left;
    }

    but on Page 2 maybe I had this...

    p {
    font-weight: bold;
    margin: 20px 10px;
    padding: 15px;
    }

    #button {
    margin: 350 px 100px, 0px 0px;
    }

    And I don't have the time to re-write things so every style is unique and be sure I don't break things as I go?!


    Just use different ids for each form and then in the styles use those ids to set different styles for each form.
    See above.

    Also, don't wrap HTML markup in <?php ?>. That's incorrect and you will get a parse error. Put only PHP code inside <?php ?>. Like this:

    PHP Code:

    <?php

    // some PHP code here...

    ?>

    <!-- some HTML markup here... -->

    <?php

    // some other PHP code here...

    ?>

    <!-- more HTML markup here... -->
    Okay.



    Amy

  21. #21
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    If you have disjointed pages then the only solution without rewriting the pages is to have x separate pages. For example, if you have 4 forms then you have 4 separate PHP files.

    step_1.php
    step_2.php
    step_3.php
    step_4.php

    Reuse requires strategy and planning. Commonalities need to be determined ahead of time otherwise you end up in the situation your in – disparate mess. The only remedy is to either identify areas of overlap and rewrite accordingly or make due and repeat commonalities that are encountered along the way in each file. Seems as if you have pigeon holed yourself. I would recommend staying on the path your on to get the job done and chalk this one up to experience.

  22. #22
    SitePoint Addict amy.damnit's Avatar
    Join Date
    Sep 2009
    Posts
    336
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    If you have disjointed pages then the only solution without rewriting the pages is to have x separate pages. For example, if you have 4 forms then you have 4 separate PHP files.

    step_1.php
    step_2.php
    step_3.php
    step_4.php

    Reuse requires strategy and planning. Commonalities need to be determined ahead of time otherwise you end up in the situation your in disparate mess. The only remedy is to either identify areas of overlap and rewrite accordingly or make due and repeat commonalities that are encountered along the way in each file. Seems as if you have pigeon holed yourself. I would recommend staying on the path your on to get the job done and chalk this one up to experience.
    Thanks for the response, but again, I have made no great sins?!

    Each page was unique and other than a tiny page header, all of the content was disparate (e.g. a table, a log-in form, a user form, an invoice, a brochure-like page).

    Different is different. Period.

    What I am working on currently is probably 5% of the finished site a year from now which will require templating.

    But the 5% I'm working on now is what helps drive 95% of the attendance and thus revenue...

    I appreciate the feedback, but we are talking apples and oranges to what I have.

    There was no poor planning. The only thing I would have done slightly differently - had I had more time - was coming up with a unified CSS style library. However that can be fixed later.


    Amy

  23. #23
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try this, it might make things easier when you get a lot of php.
    If I ever put PHP in the same page as the html display I always put it at the top.
    PHP Code:
    <?php require_once('form.php'); ?>
    <html>
    ..
    <form action="index.html" method="post">
    // You can make the form action the same page because you already included the form processing in form.php
    ...
    </form>
    </html>
    If you had several forms and wanted to use one file --you could break them down even better....
    for example by pass a value through the url (in the from action, after the ? mark)..

    PHP Code:
    <?php require_once('form.php'); ?> // You would have to simply include this on any page you want to do a form

    // pretend this is on register.php
    <form action="anypage.html?register" method="post">

    // pretend this is on login.php
    <form action="anypage.html?login" method="post">

    // pretend this is anywhere..
    <form action="anypage.html?save" method="post">
    Then in form.php you can manage each form like...
    PHP Code:
    if (isset($_REQUEST['register']))
    {
     
    //.. handle how the register form works
    }


    if (isset(
    $_REQUEST['save']))
    {
     
    //.. handle how the save form works
    }


    if (isset(
    $_REQUEST['login']))
    {
     
    //.. handle how the login form works

    I might actually be way off topic.. lol


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •