Help please - IE11 submitting form 20+ times!

Hi Guys, I wonder if you can help.
I have set up a form which then redirects to a thank you page in the way I normally would, but I am having a problem with users who are on IE 11 or Edge 1.0. There form submits over 10-20 times giving 10-20 duplicate results for them on the database table, as well as the user receiving 10-20 confirmation emails (which is more the problem)! As far as I can see from the stats the IE11 and Edge users are getting to the thank you page. Everyone else is submitting fine from other browsers.

Here is the PHP code I am using. Can anyone shed any light?
I have tried to do a header(‘Location: /thankyou.html/’); to try and instead to help but this didn’t work. I have tried replacing the submit on the html side to be an
button. Again still the same issue.

Any help gratefully received.

  <?php 
    
    if (isset($_POST['add']))
    {
    	
      include_once '../includes/db.inc.php';
     
    try
      {
        	$sql = 'INSERT INTO table SET
    	attending= :attending,
    	firstname= :firstname,
    	surname= :surname,
    	email= :email,
    	phone= :phone,
    	title= :title,
    	date = CURDATE()';
    	$s = $pdo->prepare($sql);
    	$s->bindValue(':attending', $_POST['attending']);
    	$s->bindValue(':firstname', $_POST['firstname']);
    	$s->bindValue(':surname', $_POST['surname']);
    	$s->bindValue(':email', $_POST['email']);
    	$s->bindValue(':phone', $_POST['phone']);
    	$s->bindValue(':title', $_POST['title']);
    	$s->execute();
     	 }
     	 catch (PDOException $e)
     	 {
       	 $error = 'Error on submitting.';
       	 include 'error.html.php';
       	 exit();
     	 }
      
      
     /////give a ticket number
    			
    $userid = $pdo->lastInsertId();
    $ticketnumber = 'CODE'.$userid;
    											
    try
    	{
    	$sql = 'UPDATE table SET
    	ticketnumber = :ticketnumber
    	WHERE id = :id';
    	$s = $pdo->prepare($sql);
    	$s->bindValue(':ticketnumber', $ticketnumber);
    	$s->bindValue(':id', $userid);
    	$s->execute();
    	}
    	catch (PDOException $e)
    	{
    	$error = 'Error inputting ref number.';
    	include 'error.html.php';
    	exit();
    	}
    											
    ////////////send email/////////////									
    							
    							
    	$subject = "Confirmation";
    	$headers = "From: email@email.co.uk\r\n";
    	$headers .= "Reply-To: email@email.co.uk\r\n";
    	$headers .= "Return-Path: email@email.co.uk\r\n";
    	$headers .= "MIME-Version: 1.0\r\n";
    	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    							
    							
    	$message = '
    	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    	<html xmlns="http://www.w3.org/1999/xhtml">
        	<head>
    	<body> ...lots of email coding in here...
        	</body>
    	</html>
    	';
    
    	if (mail($email,$subject,$message,$headers)) 
    			{
    			include 'thanks.html';
    			exit();
    			}
    			else
    			{
    			$error = 'Error sending.';
    			include 'error.html.php';
    			exit();
    					
    					
    	}
    
    include 'registration.php';
    
    ?>

What does your form look like?

Scott

Hi, the form and some javascript I am using is this:

<script language="Javascript">
    
function VF_hollywood(){
	var theForm = document.form1;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var errMsg = "";
	var setfocus = "";
						
	if (theForm.attendingyes.checked == false){
		if (theForm.attendingno.checked == false){
			errMsg = "Please enter if you will be attending";
			setfocus = "attendingyes";
			}
	}
						
	if (theForm.surname.value == ""){
		errMsg = "Please enter your surname";
		setfocus = "surname";
	}
					
	if (theForm.firstname.value == ""){
		errMsg = "Please enter your first name";
		setfocus = "firstname";
	}
						
	if (theForm.email.value == ""){
		errMsg = "Please enter your email address";
		setfocus = "email";
	}
						
	if (theForm.phone.value == ""){
		errMsg = "Please enter your contact telephone number";
		setfocus = "phone";
	}

	if (errMsg != ""){
		alert(errMsg);
		eval("theForm." + setfocus + ".focus()");
		}
		else theForm.submit();
	}
						
</script>
           


 <FORM name="form1" id="form1" onSubmit="VF_hollywood(); return false;" action="?" method="POST" >
             
                <p>Will you be attending?</p>
                  <table width="100%">
                    <tr>
                      <td><input type="radio" name="attending" value="attending" id="attendingyes">
                        Yes</td>
                    </tr>
                    <tr>
                      <td><input type="radio" name="attending" value="not attending" id="attendingno">
                        No</td>
                    </tr>
                  </table>
               


                  <label>Your First Name</label>
                  <input name="firstname" type="text" required class="form-control" id="firstname" autocomplete="on" value=""  placeholder="First Name" />
                  
              
                
                  <label>Your Last Name</label>
                  <input name="surname" type="text" required class="form-control" id="surname" autocomplete="on" value=""  placeholder="Last Name" />
                              
               


                  <label>Email </label>
                  <input name="email" type="email" required class="form-control" id="email" autocomplete="on" value=""  placeholder="Email" />
                 
                  
               <label>Mobile</label>
                  <input name="phone" type="tel" required class="form-control" id="phone" autocomplete="on" value=""  placeholder="Mobile Number" />
                                
                
                <input type="submit" class="btn btn-success btn-lg" value="Register" name="reg">
               
              <input name="add" type="hidden" id="add" value="add" />
            </form>

your database table has been incorrectly set up; it should be impossible to submit duplicate data.

Your code should rely on successful insertion of the data before sending an email.

Are you SURE it’s IE doing it? Or is it people hitting refresh because they get a blank screen? You will never reach the include statement at the bottom of this page.

Thanks for your reply, do you mean that I should only allow a field to be unique ie email addresses in the table therefore will reject if it is submitted again? Currently the only bit in the data that is different is the id which is auto increment, and the ticket number which gets updated with the id the rest is duplicate data.
I have captured stats from the site and only IE 11 and Edge 1 have the issue. I don’t think it’s likely that the issue is people pressing the form multiple times as the stats would show multiple visits. Also the time of the entires is exactly the same. The number of people (more than 20 so far) have this large amount of duplicate entries.
There are more than 150 entires which are fine, and have successfully reached the thank you page as well as received the confirmation email. I’m frankly baffled!! :0(

	if (mail($email,$subject,$message,$headers)) //Let's assume we get here. Either this is true...
			{
			include 'thanks.html';
			exit(); //And we stop processing here...
			}
			else //Or it's false...
			{
			$error = 'Error sending.';
			include 'error.html.php';
			exit(); //And we stop processing here...
					
					
	}
//So we never get here, because both clauses of the if have invoked exit();
include 'registration.php';

And yeah, assuming that you’re storing information about a single event in which people will be attending or not, email should be unique, which will reject additional attempts to submit with that email.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.