SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: PHP $_SERVER['PHP_SELF'] Replace Content

  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP $_SERVER['PHP_SELF'] Replace Content

    Hi, just wondering how I can change the content of page using PHP_SELF. It would be good really for use on a contact form, to remove all of the fields, etc once the user has submitted the form and to display a DIV with the usual thanks and should be in touch within twenty-four hours.

    Found site this examples what I'm trying to explain (all content is changed within the same page)! Click here to visit.

  2. #2
    Non-Member
    Join Date
    Dec 2010
    Location
    /home/pc
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the form processing script you could set a session variable after the email has been sent and then redirect back to the contact form page. When the contact form page loads, check for the existence and value of the above session variable and then use php to set the css to display the appropriate content div containing either the form or a thank you message.

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aidos View Post
    In the form processing script you could set a session variable after the email has been sent and then redirect back to the contact form page. When the contact form page loads, check for the existence and value of the above session variable and then use php to set the css to display the appropriate content div containing either the form or a thank you message.
    Hi, thanks fr your reply. Ok, sounds an interesting way to do this...are there any other ways that this could be done without using a session? Just curious!

  4. #4
    Non-Member
    Join Date
    Dec 2010
    Location
    /home/pc
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use cookies instead of sessions but not all browsers have cookies enabled.

  5. #5
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for your message. I think I'd prefer to use sessions. So now, small question, I have an admin area and have started a session so how do I write to the existing session? I also want the user to be able to click back to the page and enter more details so I'm guessing I would need to destroy (somehow) that particular session variable?

  6. #6
    Non-Member
    Join Date
    Dec 2010
    Location
    /home/pc
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually mislead you a bit because I didn't realise you were submitting the form page to itself in which case you don't need sessions at all. Sorry

    I would do something like this.

    PHP Code:
    <?php
    if(isset($_POST['submit'])) {
        
    //do some processing here and then set the class values
        //for the form and message containers
        
    $formClass 'hide';
        
    $msgClass 'show';
        unset(
    $_POST['submit']);
    } else {
        
    $formClass 'show';
        
    $msgClass 'hide';
    }
    ?>
    <!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">
        <head>
            <title></title>
            <style type="text/css">
                .show {
                    display: block
                }
                .hide {
                    display: none
                }
            </style>
        </head>
        <body>

            <form class="<?php echo $formClass?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
                <input type="text" name="txtEmail" />
                <input type="submit" value="Submit" name="submit" />
            </form>

            <div class="<?php echo $msgClass?>">
                Thank you for your email
            </div>

        </body>
    </html>

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey dude, perfect got you now, makes perfect sense! Thanks for taking the time to explain, muchly appreciated

  8. #8
    Non-Member
    Join Date
    Dec 2010
    Location
    /home/pc
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome

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
  •