...

View Full Version : php form submit/ repost problem



Roost3r
04-13-2003, 06:13 PM
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?

Spookster
04-13-2003, 06:22 PM
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">





$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

Roost3r
04-13-2003, 06:35 PM
gotcha... thx

Roost3r
04-13-2003, 07:39 PM
hrmm well its still not reposting; the isset just does the same thing my session does; but the popup thing still appears



<?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,re sizable=no,copyhistory=yes,width=535,height=355')" /></form>

Spookster
04-13-2003, 08:11 PM
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.

Roost3r
04-13-2003, 08:54 PM
because i thought that maybe that would rid the popup ;)

Roost3r
04-13-2003, 09:17 PM
i solved it... ended up using a iframe

Spookster
04-13-2003, 09:26 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum