if i pressed the submit button in the first course, this would also disable the second,third,etc course submit button too.
First, let me ask you: what if someone is in a
text field and they press
enter on the form? The form will submit, but you get no click on the button. Move your confirmSubmit to the form.
$form = "
<form action=\"yourscript.php\" method=\"post\"
onsubmit=\"return confirmSubmit(this);\">
<!-- etc. -->
<input type=\"Submit' name=\"
SubmitButton\" value=\"Submit\"/>";
</form>
";
echo $form;
Never name objects possible reserved words, like Submit, Reset, Search, etc.
Note two important additions,
return and
this as a reference to the form. This refers to the form itself. So your JS will now need two things: specific references to the form, and a return false at the end on error. Return false is what will stop the form from submitting if there is an error, if no error, return true. This is also how you keep it from affecting other forms on the page. I don't know what the JS is doing, bur examine this, it will show what I mean.
function confirmSubmit(form) {
var msg='';
if (form.some_field.value=='') {
msg = "The some field is required.";
}
if (msg=='') {
form.SubmitButton.disabled=true;
return true;
}
else {
alert(msg);
return false;
}
}
As for the PHP part, if you have multiple forms on the page, you're just going to have to name the submit buttons different names - however note the comment above, if they press enter, I'm "pretty sure" there will be no $_POST['SubmitButton']. Safer to use a hidden field. like <input type="hidden" name="Form1" value="1">,
$disabled_buttons=Array();
$forms = Array('Form1','Form2','Form3','Form4');
foreach ($forms as $form) {
$disabled_buttons[$form] = (($role== 'user') and isset($_POST[$form]))?' disabled="disabled"':null;
}
... <input type=\"Submit\" name=\"SubmitButton\" value=\"Submit\"". $disabled_buttons['Form1'] ."/>";