/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] IE7 submits form twice – how to stop it?

Hello, everyone.

I am working on a form that submits once when the submit button is clicked if it’s being accessed in FF8 or Chrome, but is submitting twice when the browser is IE7. I suspect IE8 and IE9 will submit twice, too, although that is not tested.

It’s quite a lengthy form, so I won’t post the form code, but I will give a small example, here:

[CODE]
<form action=”register_action.php” method=”post” enctype=”application/x-www-form-urlencoded” name=”registrationForm” id=”registrationForm”>

There are several input type=”text”, two type=”password”, and several selects.

There are NOT any type=”file” or anything else.

At the bottom is one type=”submit” and one type=”reset”.

</form>
[/CODE]

I am not using JavaScript to submit the form; I am letting the form submit itself by way of the <input type=”submit”>.

Is there a way to get this to not submit twice in IE?

Thank you,

to post a comment
HTML

14 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscJan 05.2012 — 1) Got a link?

2) How do you know it's submitting twice? What leads you to this conclusion?

3) Has your HTML been validated? Long shot, but taking a look at any errors might trigger something...


EDIT:

4) Are you positive that no JS is involved? i.e. Have you disabled JS and tried to submit your form?
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 05.2012 — Hi, aj_nsc, thank you for replying.

1) Unfortunately, no. I am working on a dev server that I built from an old desktop that is only accessible from my internal network. There is no port forwarding on my router, my IP address changes daily (Uverse), and I do not have a dynamic DNS account. Which is how I prefer it, as I'd rather not have script-kiddies trying to break my stuff while I'm still creating it. ? Or at all, really, but it totally sucks when developing.

2) I'm using PHP for server-side form validation that redirects back to the form if something needs correcting and throws a JavaScript alert; when I have something that needs correcting, I am seeing the JavaScript alert twice in IE7, but only once in FF and Chrome.

3) DreamWeaver is not showing any errors, nor is FireBug. I can't use an online validator for the same reason in #1. I suppose I could look for a "copy/paste" validator and try that, but don't know if the PHP will throw it off.

4) JS is not involved in SUBMITTING the form, I am letting the form do the submitting. I am using JS for user name input masking (no numbers, no special characters other than - and '), and jQuery for qTip2 and CurvyCorners.

If you like, I _can_ post all of the document, here. Just didn't want to do it off the bat considering how lengthy it is.
Copy linkTweet thisAlerts:
@aj_nscJan 05.2012 — #2 has intrigued me. How does the JS alert showing twice means the form was submitted twice?

To me, that just means that the function showing the alert is called twice, or something of that nature.

You might want to post the PHP/JS code related to error-handling and the alert.
Copy linkTweet thisAlerts:
@hamburglarJan 05.2012 — By any chance are using the Dreamweaver form validation?
Copy linkTweet thisAlerts:
@LechlakJan 05.2012 — I had this problem previously. The way around it is on the client side in the js use on submit = true and disable the form.

Works like a charm.
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 05.2012 — @aj_nsc, here is the actual (not generated) code that throws the alert. If a PHP session variable called "notNice" exists, it causes JavaScript to alert whatever message is generated server-side during SS validation. At the bottom of the index.php page (which contains an include for "register.php" that actually contains the form) is PHP code that says "IF session['notNice'] exists, delete it."

[code=php]
<script language="JavaScript1.5" type="text/javascript">
<?php if(isset($_SESSION['notNice']) && !empty($_SESSION['notNice'])) { ?>
// Save SS validation message to a JS variable
alertVal = "<?php echo $_SESSION['notNice']; ?>";
// Replace "<br>" in validation message with JS new line (n)
alertVal = alertVal.replace(/<br>/g,"n");
// Alert message with proper new line commands
alert(alertVal);
<?php } ?>
</script>
[/code]


I am using PHP "ob_start()" and "ob_end_flush()" to buffer output, which is only sent once everything has been generated by the server. So I'm thinking that the double alerts are caused by the form being rejected by the server twice. The fact that it works just fine in FF and Chrome gives credibility (in my eyes) to this theory (I hate IE, never liked it or developing for it.)

@hamburglar, yes, I am using DW form validation.

@Lechlak, huh?
Copy linkTweet thisAlerts:
@LechlakJan 05.2012 — Ahaha Apparently I should be more clear.

Use javascript to disable the form on submit.
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 05.2012 — I'll give that a shot. Disable after submit. I'll report what happens. Thanks.

Apparently, once a form is submit you can't disable the form, itself. Maybe the submit button, but that's not the same thing. ?
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 06.2012 — Okay, I couldn't find an online PHP validator. But I did find an online HTML validator and then copied and pasted the generated HTML into an .html file and uploaded it to the validator.

Don't remember which one I used, but it isn't very good. It kept telling me that my <select> tags weren't closed (they were, even in the generated HTML), that "selected" is invalid for options, and then informed me that "onChange", "onBlur" and "onFocus" were not valid.

That was pretty much it.

I'm willing to admit that maybe the form isn't being submit twice; but if it isn't, what could be causing the double-alert when validation kicks?

Thanks,
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 09.2012 — After some more testing, I now realize that the form is not being submit twice. A successful validation will submit one record to the database, not two.

But this still begs the question: When a field does need correction, why does the alert appear twice?

Any other thoughts on the issue?

Thanks,
Copy linkTweet thisAlerts:
@LechlakJan 10.2012 — Can you post your js for the client side validation?
Copy linkTweet thisAlerts:
@LechlakJan 10.2012 — Thanks - taking a look at it in the near future.
Copy linkTweet thisAlerts:
@WolfShadeauthorJan 13.2012 — It's [I]kind of[/I] fixed. I moved the JS to the bottom of the main page instead of at the top. Don't ask me why, but this cured IE of the double-alert.

I hate IE. All of them.
×

Success!

Help @WolfShade spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...