SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    after alert, return viewer to a form with data still filled in

    If a viewer fills in a form such that an error in one field brings up an alert, how do return the viewer to the form with the rest of the fields still filled in?

    The code below returns the viewer to the form, but the fields are empty.

    [PHP] //check that the user has entered the same email address twice
    if ( ($_POST["email_address"]) != ($_POST["email_address_verify"]) ) {
    ?>
    <script language="JavaScript">
    <!--
    alert("The two e-mail addresses you just entered don't match. Please try again.");
    document.location.href="<? echo($_SERVER["HTTP_REFERER"]); ?>";
    // -->
    </script>
    <?
    }
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing:
    document.location.href="<? echo($_SERVER["HTTP_REFERER"]); ?>";
    to:
    history.go(-1);

  3. #3
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'll give it a try.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  4. #4
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried:

    PHP Code:
     //check that the user has entered the same email address twice 
    if ( ($_POST["email_address"]) != ($_POST["email_address_verify"]) ) {
    ?>
     
    <script language="JavaScript">
    <!--
    alert("The two e-mail addresses you just entered don't match. Please try again.");
    //document.location.href="<?//echo($_SERVER["HTTP_REFERER"]); ?>";
    history.go(-1);
    // -->
    </script> 
     
    <?
    It doesn't work, i.e. keep the data entered into the form after returning to it.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, maybe it's just my browser (ie6) that keeps the settings, but it works ok for me.

    Is your page online? I'll check it out.

    You can store all the form data in session variables and on your form page check if they contain data and use them to repopulate the form elements, it's clunkier but it'd work.

  6. #6
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jim,

    You can see the page online at in my test area at:

    http://test.kripalu.org/ctlg_order.php
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep all the fields are filled in after the alert...

    That's a shame, what browser are you using?

  8. #8
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using IE 6.0.
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  9. #9
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm. I also tried

    Code:
    history.back();
    .

    The script is now:

    Code:
     <script language="JavaScript">
    <!--
    alert("The two e-mail addresses you just entered don't match. Please try again.");
    //document.location.href="<?//echo($_SERVER["HTTP_REFERER"]); ?>";
    //history.go(-1);
    history.back();
    // -->
    </script>
    This is very odd, as
    Code:
    history.back();
    seems to work on other sites of mine, i.e.
    http://www.clickbasics.com/catalog.php

    There I use common.php as an include:

    <?php // common.php
    function error($msg) {
    ?>
    <html>
    <head>
    <script language="JavaScript">
    <!--
    alert("<?php echo $msg?>");
    history.back();
    //-->
    </script>
    </head>
    <body>
    </body>
    </html>
    <?php
    exit;
    }
    ?>


    I wonder what the difference could be?
    Last edited by paulcj2; Jan 11, 2005 at 09:47.
    Paul C.
    ClickBasics
    http://www.clickbasics.com


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
  •