SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: keep form data

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    keep form data

    Hi guys

    In my forms when they are submitted and the user enters a error say a empty field. how can I keep the data in the fields, at the moment all the fields go blank when they go back to the form

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use session for this.

  3. #3
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using sessions

  4. #4
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just insert your post variables back into the fields. Just be sure to use htmlspecialchars on them.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  5. #5
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you have a tutorial?

  6. #6
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // nowhere.php
    <?php
        session_start
    ();
    ?>
    <form method='post' action='somewhere.php'>
        <input type='text' name='name' value='<?=$_SESSION['name']?>' />
        <input type='submit' name='submit' value='Submit' />
    </form>

    // somewhere.php
    <?php
        session_start
    ();
        
    $_SESSION['name'] = $_POST['name'];
        
    header("Location: nowhere.php");
    ?>


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
  •