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
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php form submit/ repost problem

    Hi, currently my guest book works like this:
    its on my index.php page; i have it posting to itself; so after someone presses submit it will post to index.php and update the guestbook display... now normally if they press refresh it will repost if they press retry in teh dialog window that pops up.... so im using the session to make sure they cant repost within 300 seconds; but that just prevents the repost; the dialog still appears

    i want to either get rid of that pop up dialog or stop the form from reposting on refresh; all with the form still posting to itself

    any solution?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    One way to stop reposting from doing a refresh is to check for a value set by the submit button. So surround your script with something like this:

    assuming your submit button is something like this:

    <input type="submit" name="submit" value="Post">


    PHP Code:

    $submitButton 
    $_POST["submit"];

    if(!isset(
    $submitButton)){
    //post a reply

    so basically it reads like this:

    if your submit button has not been clicked and had a value set then post a reply otherwise don't post a reply
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gotcha... thx

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hrmm well its still not reposting; the isset just does the same thing my session does; but the popup thing still appears

    PHP Code:
    <?php
      $submit 
    $_POST["submit"]; 
      if (isset(
    $submit))
      {
          if(!isset(
    $_SESSION['last_post']) || $_SESSION['last_post']<mktime())
          {
             
    $myname nohtml($myname);
             
    $myso nohtml($myso);
             if (
    $myname <> "" $myso <> "")
             {
               
    $myso smilies($myso);
               
    $myso badwordfilter($myso);
               
    $myname badwordfilter($myname);
               
    $addshoutoutstr "INSERT INTO shoutout (name, shoutout) VALUES ('$myname', '$myso')";
               
    $addshoutout mysql_query($addshoutoutstr) or die("Database Insert Query Error");
              
               
    $_SESSION['last_post']=mktime()+180;
             }
          }
          else
          {
             
    $wait $_SESSION['last_post'] - mktime();
             echo 
    "<tr><td colspan=\"2\"><b>You have to wait $wait seconds before posting again.</b></td></tr>";
          }
      }

     
    $soquery mysql_query("SELECT * from shoutout ORDER BY id DESC LIMIT 8"$db) or die("Database Retrival Error");
     
    $count 0;
     while (
    $soloop mysql_fetch_array($soquery))
     {
         
    printf("<tr><td valign=\"top\" class=\"borders\"><b>%s</b></td><td class=\"borders\"><small>%s</small></td></tr>\r\n"stripslashes($soloop['name']), stripslashes($soloop['shoutout']));
     }
    ?> 
    <form method="post" action="<?=$_SERVER['PHP_SELF']; ?>" class="myform"> 
                 <div align="center">&nbsp;&nbsp;<font color="white"><b>Name:</b></font>&nbsp;<input type="text" name="myname" size="10" class="mysearch" maxlength="18" /><br />
                 &nbsp;&nbsp;&nbsp;&nbsp;<font color="white"><b>Msg:</b></font>&nbsp;<input type="text" name="myso" size="10" class="mysearch" maxlength="60" /></div>
                 <div align="center"><input type="submit" value="Submit" name="submit" id="submit" />
                 <input type="button" value="Smilies" onclick="window.open('http://www.xtremehw.com/smilies.html','Smilies','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=535,height=355')" /></form>
    Last edited by Roost3r; 04-13-2003 at 07:59 PM.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts

    Re: php form submit/ repost problem

    Originally posted by Roost3r
    i want to either get rid of that pop up dialog or stop the form from reposting on refresh; all with the form still posting to itself

    any solution?
    I thought that was what you asked for.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    because i thought that maybe that would rid the popup

  • #7
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i solved it... ended up using a iframe

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well instead of using an iframe what the best way is to remove the actual code for doing the processing out of that page and put it into another page that does nothing but processing and then redirects back to the index page. Then when people refresh the page it will simply refresh the page and not submit the information again and get that dialog box.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

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