Disabled submit button prevents form submission
Moderator: General Moderators
-
Robert K S
- Forum Newbie
- Posts: 11
- Joined: Thu Dec 18, 2003 7:06 pm
- Location: Cleveland, Ohio
Disabled submit button prevents form submission
I have a web form that submits to itself--a guestbook, for example. I have tried all the usual JavaScript techniques for disabling the Submit button (to prevent inadvertant multiple submissions), but they also prevent proper functioning of the page.
The PHP code in the page that tests whether the form has been submitted is
if (isset($_POST['submit']) && $_POST['submit'] == 'Add guestbook entry') {
// Error-check, then insert entry into database rather than displaying the form again
}
But this condition always fails, and I'm wondering why. Is it because the submit button has been disabled?
Can anyone help?
The PHP code in the page that tests whether the form has been submitted is
if (isset($_POST['submit']) && $_POST['submit'] == 'Add guestbook entry') {
// Error-check, then insert entry into database rather than displaying the form again
}
But this condition always fails, and I'm wondering why. Is it because the submit button has been disabled?
Can anyone help?
you could test it out with this:
if you dont see the submit button after submitting then its prolly cos of disableing it.
Code: Select all
<?php
foreach($_POST as$key => $value)
{
echo $key ." => ". $value."<br />";
}
?>There is a real easy way of doing this which I tend to use now and again to prevent the same form being submitted more than once. I normally use it on forms that upload graphics to a site (like avatars for example).
What you do is add a hidden input to the form and check it's value when the form is submitted. Here's an example...
** Notice I don't use a true "submit" button.
** The <fieldset> is optional obviously but is required for XHTML documents.
What you do is add a hidden input to the form and check it's value when the form is submitted. Here's an example...
** Notice I don't use a true "submit" button.
** The <fieldset> is optional obviously but is required for XHTML documents.
Code: Select all
<form id="myForm" method="POST" action="somewhere.php">
<fieldset>
<input type="hidden" name="sent" value="no" />
<input type="text" name="anInput" value="aValue" />
<input type="button" value="SUBMIT" onclick="if(this.form.elements.sent.value=='no') {this.form.elements.sent.value='yes'; this.form.submit()}" />
</fieldset>
</form>-
Robert K S
- Forum Newbie
- Posts: 11
- Joined: Thu Dec 18, 2003 7:06 pm
- Location: Cleveland, Ohio
Qads: No need for the loop, print_r($_POST) will do. In any case, what would the workaround be? Has anyone else use gotten a script that submits to itself to work with a disabling submit button?
Gen-ik: There's no XHTML requirement for the <fieldset> tag--it's just a neat way to group form data when combined with the <label> tag.
Gen-ik: There's no XHTML requirement for the <fieldset> tag--it's just a neat way to group form data when combined with the <label> tag.
Last edited by Robert K S on Sat Dec 20, 2003 12:09 am, edited 1 time in total.
-
Robert K S
- Forum Newbie
- Posts: 11
- Joined: Thu Dec 18, 2003 7:06 pm
- Location: Cleveland, Ohio
-
Robert K S
- Forum Newbie
- Posts: 11
- Joined: Thu Dec 18, 2003 7:06 pm
- Location: Cleveland, Ohio
"I've checked and tested it at W3Schools.com"
So what you're saying is, you added an extraneous <fieldset> tag to a form and the validator didn't return an error. Why should that surprise you?
I bet if you remove the <fieldset> tag the form will validate just the same. <fieldset> is merely a graphical shortcut for drawing a pretty box around whatever elements it encloses. Actually, I don't find it very aesthetically pleasing at all--so it's good it's not an XHTML requirement.
So what you're saying is, you added an extraneous <fieldset> tag to a form and the validator didn't return an error. Why should that surprise you?
I bet if you remove the <fieldset> tag the form will validate just the same. <fieldset> is merely a graphical shortcut for drawing a pretty box around whatever elements it encloses. Actually, I don't find it very aesthetically pleasing at all--so it's good it's not an XHTML requirement.
No it was the other way around.Robert K S wrote:"I've checked and tested it at W3Schools.com"
So what you're saying is, you added an extraneous <fieldset> tag to a form and the validator didn't return an error. Why should that surprise you?
I bet if you remove the <fieldset> tag the form will validate just the same. <fieldset> is merely a graphical shortcut for drawing a pretty box around whatever elements it encloses. Actually, I don't find it very aesthetically pleasing at all--so it's good it's not an XHTML requirement.
The first time I tested a Strict XHTML page with a <form> in it (with the W3C validator) it spat out an error telling me that the <fieldset> was missing from the <form>.
I agree that they don't look nice so I just 'hide' them with a <style>. If you set the border and margin to 0px then the <fieldset> doesn't show up.
Give it a try. Create a simple Strict XHTML page with a form in it (and no fieldset) and see what the validator tells you. You'll find it here... http://www.w3schools.com/site/site_validate.asp