Jump to content

Recommended Posts

Hello, guys. I'm using the following code to send me an automated mail in case the user find a broken link. But there are 2 problems: 1) after submitting I'd rather not disrupt their game by refreshing the page. So, is there any way to send mail without the post refreshing? 2) if the user hits F5, the page reloads and the code runs again, sending two or more times the same email. How can I avoid duplicated emails caused by manual browser refresh?

 

(the most important solution currently is how to to avoid duplicated entries, in case an ajax solution is too hard to post here.)

 

<form name="fbrlink" action="<?= $_SERVER['PHP_SELF']."?page=ok" ?>" method="post">
<?php
echo('<input name="sbrlink" id="B1" type="button" value="broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" onclick="this.form.submit();"/>');
?>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{ if ($_SERVER['QUERY_STRING'] == 'page=ok') {
echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>';
mail("contact@ctt.net","report broken link","Game notified:MarioBros");
echo '<script type="text/javascript" >document.fbrlink.sbrlink.disabled = true;</script>';
?>
<script type="text/javascript" >document.fbrlink.action='<?php echo $a; ?>';
alert('<?php $_SERVER['QUERY_STRING'];?>');
</script>
<?php
}
else  {}
}else{
}
?>

After you send the mail you could set a cookie or session var like $sent = true or something, and test against it everytime. Just my 2 cents :)

 

I've never needed a cookie before. How can I use a cookie?

 

 

You could process your form before page output.  Immediately after form processing, refresh the page.  Then they can hit f5 all they want, and the form will not process again. Until they submit it, again.

jcbones, I didn't understand what you mean. How can I use a submit before a <HTML> tag? how this will prevent the browser update?

 

Thank you for your answers.

Ideally all processing should reside outside of HTML output.  This way you can manipulate the page the way you would like.

 

You can run this script as a test, to show you what I'm talking about.

 

<?php
if(isset($_POST['submit'])) {
header('Status: 200');
header('Location: ' . $_SERVER['PHP_SELF'] . '?pass=true');
}
elseif(isset($_GET['pass'])) {
$message = 'You have successfully posted the form, now hit f5 for refresh.';
}
else {
$message = 'Please submit the form.';
}

?>
<html>
<head>
<title>Test</title>
</head>
<body>
<?php echo $message; ?>
<form action="" method="post">
<input type="text" value="test" name="test"/>
<input type="submit" name="submit" value=" SUBMIT " />
</form>

 

really, jcjones, the ideal is to use a separate page, but this a game site and there is no need to redirect them to other page, even if it doesn't works.

 

I've put your code at the beginning of the php file, but the button doesn't submit (for example, I can't see the alert generated by js. ) I also have put only the following piece..

echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>';
mail("contact@ctt.net","report broken link","Game notified:MarioBros");
echo '<script type="text/javascript" >document.fbrlink.sbrlink.disabled = true;</script>';

...after your phrase $message = 'Please submit the form.';

what causes continuous mail sending, even if I don't click the button submit.

 

where's the error??

I will start honestly, I aint bothered reading everything above.

 

All I saw was

Mail Form

Multiple

Refresh

 

Anyway, Are you using any Captchas to stop bots using your form.

 

Most of these fail if the form has been re-submitted (Refreshed)

 

A very popular / Good Captcha, is googles recaptcha (They bought it early this year I think)

 

http://www.google.com/recaptcha

 

 

1. This confirm box.

echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>';

 

Will not keep this code from running.

mail("contact@ctt.net","report broken link","Game notified:MarioBros");

 

If you would post the entire script, then I would fix it for you.  My lessons don't seem to be helping.

 

Ok, let's post it. Here's the code:

 

<?php
if(isset($_POST['submit'])) {
header('Status: 200');
header('Location: ' . $_SERVER['PHP_SELF'] . '?pass=true');
}
elseif(isset($_GET['pass'])) {
$message = 'You have successfully posted the form, now hit f5 for refresh.';
}
else {
$message = 'Please submit the form.';
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>

<body id="index" class="standard" >

<form name="fbrlink" action="" method="post">
<p>
<?php
echo('<input name="sbrlink" id="B1" type="button" value="Broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" onclick="this.form.submit();"/>');
?>

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') 
{ if ($_SERVER['QUERY_STRING'] == 'page=ok') {
$a=$_SERVER['PHP_SELF'];
echo '<script type="text/javascript" >confirm("Click OK to notify us.");</script>'; 
mail("contact@ctt.net","report broken link","Game notified:MarioBros");
echo '<script type="text/javascript" >document.fbrlink.sbrlink.disabled = true;</script>';
?> 
<script type="text/javascript" >document.fbrlink.action='<?php echo $a; ?>';
alert('<?php $_SERVER['QUERY_STRING'];?>');
</script>
<?php
}
else  {}
}else{
}
?>
</p>
</form>
</body>
</html>

 

Thanks in advance.

Try this, and report back, ... Please.

 

<?php
$javascript = NULL;
if(isset($_POST['sbrlink'])) {	
	if(mail("contact@ctt.net","report broken link","Game notified:MarioBros")) {
		header('Status: 200');
		header('Location: ' . $_SERVER['PHP_SELF'] . '?pass=true');
		exit();
	}
	else {
		$message = 'There was an error, when trying to contact us. Please try again.';
	}
}
elseif(isset($_GET['pass'])) {
$message = 'Thanks for the notification, we will address it shortly.  Sorry for your inconvienence.';
$javascript = '<script type="text/javascript" >document.getElementById(\'sbrlink\').disabled = true;</script>';
}
else {
$message = NULL;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body id="index" class="standard" > 
<form id="fbrlink" action="" method="post" onsubmit="return confirm('Click OK to notify us.');">
	<p>
	<?php echo $message; ?>
		<input id="sbrlink" name="sbrlink" type="submit" value="Broken Link?" style="border:none; background-color:#FFFFFF; font-family:Trebuchet MS; font-size:15px; font-weight:bold; color:#1A4877; cursor:pointer; display:block; text-decoration:underline;" />
	<?php echo $javascript; ?>
	</p>
</form>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.