#1
  1. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    How to reload the same page with a form after submit?


    I have a page with a form, and the code to process the form answers, I want the same page/form to just reload when the user presses submit.

    The only function I have found is that location command.

    PHP Code:
    header("Location:skills.php"); 
    Unfortunately this will return errors if other header info was already used in the page.

    Maybe there is something I missed in my searches, anyone have any tips for me on a good way to do this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0

    Um...


    If I understand you correctly then you should just set the form's action to the current page.
    PHP Code:
    <form action="<?php echo $PHP_SELF?>" method="post">
    or
    PHP Code:
    <form action="thispage.php" method="post"
    Eclipce
  4. #3
  5. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    Already doing that


    I have that in place.

    I process the form on the same page so I am using that already.

    It's after the form is processed, I then want to re-display/reload that page immediately with the updated values that were entered.
  6. #4
  7. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    32
    I dont see how location doesn't work for you here, but you could use meta.
    And you know I mean that.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    15
    Just make sure you update the data before you display them, there should be no need for reloading, as soon as the form has been processed the data has been updated and you can display the new data. Please give us some more specific details if this doesn't help.
    --
    Regards
    André Nęss

    Puritanism: The haunting fear that someone, somewhere may be having fun
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Pittsburgh PA USA
    Posts
    137
    Rep Power
    16
    Is this perhaps what you are concerned about?

    Red <input type="radio" name="color" value="#FF0000" <?php if ($color == "#FF0000") print("checked"); ?> >

    That is you need to redisplay information in some other format, or you are getting it from a hidden variable?

    Alex
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2001
    Location
    Toronto, Ontario, Canada
    Posts
    631
    Rep Power
    14
    andnaess is right, but if you want to keep the values if you refresh the page:

    if (!isset($action)) || $action=="Refresh") {
    ?>
    <form action="page.php" method="post">
    <input type="text" name="text1" <? if(isset($text1)) echo "value=\"$text1\"" ?>><br>
    <input type="text" name="text2" <? if(isset($text2)) echo "value=\"$text2\"" ?>><br>
    <input type="submit" name="action" value="Submit">
    <input type="submit" name="action" value="Refresh">
    </form>
    <?
    }

    else {
    // form submission
    }

    ?>
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Sydney
    Posts
    41
    Rep Power
    14
    zewt,

    Use

    echo "<meta http-equiv=refresh content=\"0; URL=skills.php\">";

    instead of

    header("Location:skills.php");


    You won't get the header info error...
    % gdb core tzuchunc
  16. #9
  17. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    Yahoo, whew.


    Thanks alot, that worked great.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jul 2001
    Location
    Oslo
    Posts
    1,516
    Rep Power
    15
    ... But it is a dreadful solution. For every access to the page your server will take two hits, and the user has to load the page twice. No good. There is clearly something else wrong with the way your app is written since you actually need to reload the page.
    --
    Regards
    André Nęss

    Puritanism: The haunting fear that someone, somewhere may be having fun
  20. #11
  21. PHP user-in-training
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Sacramento Calif. USA
    Posts
    677
    Rep Power
    0

    Well I want to do the right thing...


    Ok I will give this a try and see what happens.

    PHP Code:
    if (!isset($action)) || $action=="Refresh")


    ?> 
    <form action="page.php" method="post"> 
    <input type="text" name="text1" <? if(isset($text1)) echo "value=\"$text1\"" ?>><br> 
    <input type="text" name="text2" <? if(isset($text2)) echo "value=\"$text2\"" ?>><br> 
    <input type="submit" name="action" value="Submit"> 
    <input type="submit" name="action" value="Refresh"> 
    </form> 
    <? 


    else { 
    // form submission 


    ?>
    Thank you for the feedback everyone.

IMN logo majestic logo threadwatch logo seochat tools logo