Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder zfred09's Avatar
    Join Date
    Dec 2006
    Posts
    69
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Question Keeping Form Values After Error Message

    Ok I have multiple forms (for registration) and if someone were to fill out all the information but have an error in what they entered, how do I keep the form values they entered in the form after they get an error message? Basically so they don't have to re-type all their information after one little error.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Send the values and the error back to the form page, and display the error message(s) above the correct field(s) and use the 'default' attribute in each input field to display the value.

    Or where you looking for a more concrete example?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    In the value attribute in the html check if it's been set:
    PHP Code:
    <input type="text" name="first" value="<?php echo (isset($_POST['first'])) ? $_POST['first'] : ''?>"
    Good luck;

  • #4
    New Coder zfred09's Avatar
    Join Date
    Dec 2006
    Posts
    69
    Thanks
    0
    Thanked 5 Times in 5 Posts
    What does the default value attribute do?

  • #5
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    My bad, I meant 'value', not 'default'...

    Mental lapse
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #6
    New Coder zfred09's Avatar
    Join Date
    Dec 2006
    Posts
    69
    Thanks
    0
    Thanked 5 Times in 5 Posts
    It's aight, I don't really get how the isset works or how to implement it.

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by Brandoe85 View Post
    In the value attribute in the html check if it's been set:
    PHP Code:
    <input type="text" name="first" value="<?php echo (isset($_POST['first'])) ? $_POST['first'] : ''?>"
    Good luck;
    That is how you implement it. If the $_POST var is set, then you know the form has been submitted, if it hasn't you know that you do not need to display the $_POST value, because it doesn't have a value.

    Notice, $_POST['first'] relate to the name in your input field...see?

  • #8
    New Coder zfred09's Avatar
    Join Date
    Dec 2006
    Posts
    69
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Ya I understand now, I got it working, in my processing file I just used the value sent by the form and assigned it to a session variable, and then in my form I put value="<?php echo ("$sessionvar"); ?>". Thanks for your help.
    Last edited by zfred09; 12-23-2006 at 10:31 PM. Reason: Figured it out.


  •  

    Posting Permissions

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