SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form processing script losing link to css

    Hello,
    not quite sure under what category to place this in so I'll post it here..

    Hello,
    I found a dynamic page tutorial from youtube and for most part it works.

    Problem area: css is lost when the data entry form returns back from processing the user information.

    What I have:
    Index.php -> Menu, Css information.
    /template/contact.php - > user entry form
    /inc/formprocessing.php -> handles the user entry from and returns back to contact.php

    research:
    the CSS link is located in index.php. When contact.php calls the formprocessing.php to do its thing and returns back to the calling page(contact.php) the CSS is lost. Basically the contact.php no longer has a link to the CSS when fromprocessing.php returns back to contact.php.

    How can I fix this small problem?

    index.php

    PHP Code:
    html>
    <head> 
    <title> Website </title> 
    <link rel="stylesheet" type="text/css" href="css/style.css">

    </head>

    <body>

    <div id="header"> <h1> Website </h1> </div>
    <div id="menu">  
        <a href="index.php"> Home </a>
        <a href="index.php?p=aboutus"> About us </a>
        <a href="index.php?p=contactus"> Contact us </a>
        <a href="index.php?p=news"> News </a>
     </div>
    <div id="content" >
    <?php
        $pages_dir 
    'template';
        if (!empty(
    $_GET['p']))
        {    
    $pages scandir($pages_dir0);
            unset(
    $pages[0], $pages[1]);
            
    $p $_GET['p'];
            if(
    in_array($p '.inc.php'$pages))
            {    include (
    $pages_dir '/' $p '.inc.php'); }
            else
            {    echo 
    'Sorry, page not found'; }
        }
        else
        { include (
    $pages_dir.'/home.inc.php'); }
    ?>
    </div>

    </body>
    </html>
    contact.php
    PHP Code:
    <?php
    if($_POST['btl_save'])
    {    echo 
    $testVar;}
    ?>
    <h3> Contact us </h3>
    <form action="inc/formprocessing.php" method="post">
    <div class="testcss">
    First name: <input type="text" name="fname"  /> <br/>
    Last name:  <input type="text" name="lname"  /> <br/>
    <input type="submit" name=btl_save">
    </div>

    formprocessing.php
    PHP Code:
    <?php
    $testVar 
    'test from form processing.php';
    include(
    '../template/contactus.inc.php');

    ?>
    Last edited by robin01; Mar 13, 2013 at 08:32. Reason: entered the wrong file name in example

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by robin01 View Post
    index.php

    Code:
    	<a href="index.php?p=contactus"> Contact us </a>
    formprocessing.php
    Code:
    include('../template/contactus.inc.php');
    One of these things is not like the other....
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    One of these things is not like the other....
    The index.php process each file and associates the link to the actual file, scripted for security.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Index.php holds the link to the CSS.
    If formProcessing.php doesnt include index.php, you'll never get the CSS link.

    point formprocessing.php's include to index.php?p=contactus.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you saying include(formprocessing.php) in to index.php or include(index.php) into form processing?

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    the latter.
    include('../index.php?p=contactus');

    OR
    $_GET['p'] = 'contactus';
    include('../index.php');
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, I'm late to the party, but I'm a tad confused. First off, what is the purpose of formprocessing.php, is it meant to handle ALL forms or just the form from contact.php?

    Then I'm confused about "returns back to contact.php", do you expect the URL in the address back to be "index.php?p=contactus"? Or just to see the contact us form again?
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    canada
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    Okay, I'm late to the party, but I'm a tad confused. First off, what is the purpose of formprocessing.php, is it meant to handle ALL forms or just the form from contact.php?

    Then I'm confused about "returns back to contact.php", do you expect the URL in the address back to be "index.php?p=contactus"? Or just to see the contact us form again?
    Hello cpradio,

    1. the formprocessing.php handles the user entry form contact.php and returns back to the contact.php
    2. the script i found is from a tutorial site so i just kept the wording contact.php, but having said that, it doesnt matter which page i click on it still losses the link to the css.
    3. my plan was to bring the user back to the contact(it could be any form) form, with a message stating updated database and have the message fade out and have a blank form to submit new information.

    Im not expert at programming and not sure if the script allows me to have the css link to each page with the way i have setup. Basically the CSS is located in the index.php script and its not trickling down to other pages.

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,071
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Okay, with that said, I'm going to take a slightly different approach, so please bear with me.

    index.php - leave as is
    PHP Code:
    <html>
    <head> 
    <title> Website </title> 
    <link rel="stylesheet" type="text/css" href="css/style.css">

    </head>

    <body>

    <div id="header"> <h1> Website </h1> </div>
    <div id="menu">  
        <a href="index.php"> Home </a>
        <a href="index.php?p=aboutus"> About us </a>
        <a href="index.php?p=contactus"> Contact us </a>
        <a href="index.php?p=news"> News </a>
     </div>
    <div id="content" >
    <?php
        $pages_dir 
    'template';
        if (!empty(
    $_GET['p']))
        {    
    $pages scandir($pages_dir0);
            unset(
    $pages[0], $pages[1]);
            
    $p $_GET['p'];
            if(
    in_array($p '.inc.php'$pages))
            {    include (
    $pages_dir '/' $p '.inc.php'); }
            else
            {    echo 
    'Sorry, page not found'; }
        }
        else
        { include (
    $pages_dir.'/home.inc.php'); }
    ?>
    </div>

    </body>
    </html>
    contact.inc.php - updated
    PHP Code:
    <?php
    if($_POST['btl_save'])
    {
       
    // update database, write out success message (or error if validation fails)
        
    echo $testVar;
    }
    ?>
    <h3> Contact us </h3>
    <form action="?p=contactus" method="post"> <!--// Updated action attribute //-->
    <div class="testcss">
    First name: <input type="text" name="fname"  /> <br/>
    Last name:  <input type="text" name="lname"  /> <br/>
    <input type="submit" name=btl_save">
    </div>
    </form>
    formprocessing.php is no more (not needed)

    Okay, so here is the basics of the setup, everything is routed through index.php, so the stylesheet references, etc will be available all of the time.

    The templates, are responsible for saving/processing their own form data, however, this also introduces a limitation, that you can't use header() or setcookie() within a template as output is already started (there are ways of fixing that, so if it is of concern, just say so).
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


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
  •