i have a form being filled. i don't want the user to be able to submit twice. how can i either prevent the user from going back or disable the submit button?

i am currently disabling the submit button but when the user clicks back(from the next page) it asks whether it should resend data. when the data is resent it loads the original version of the page(without submit disabled).

can someone help me with this? thanks.

Recommended Answers

All 15 Replies

are you using asp or any other server side scripting language ?

i'm using javascript

i'm using javascript

javascript is for client side

anything for server side ?

can't think of anything
i'll post back if i can figure a way out...

but if you aren't using any client side scripting language , how are you saving the data ?

saving it to a file using php..is that a scripting language?

saving it to a file using php..is that a scripting language?

yeah..... :)

i tried using sessions..
i set a sessions variable to 1 if the form data was submitted.
i check if the the variable is one on the concerned page and if it is i call a function which disables the submit button. but this doesnt work either. any thoughts about this?

heres the code

<?php
if($_SESSION['disable']==1){
echo "<script type="text/javascript"> disablesbmt(); </script>";
}
?>

i jus realised my form acts weird too when i try the same....
please share the solution if you find one ...

I don't think you can stop a user going back if he wishes by simply clicking on the browser back button.
What you can do instead is to set session variables as he visits each stage. If he resubmits a page that has it's session variable already set then you can indicate your preferred error message (using php).
example

<?php
if($_SESSION['user_details_form_submitted']==1){
echo "You are not allowed to resubmit!!";
exit();
}
?>

Put this at the top of the script doing the validation.
Hope it helps!!!

can i put php inside javascript?

nopes....
u write javascript in the script tags...
and all u can do is call functions from the body...

what are you trying to do ?

Yes you!! can put PHP into javascript but PHP will be executed first and thus it will only print whatever you have specified into the javascript code. Like in this example:

<?php
$myname="ronaldinho gaucho";
 ?>
<script type="text/javascript">
function showMyName()
{
alert("My name is "+<?php echo "\"".$myname."\""; ?>);
}
</script>
<body onload="showMyName()">
</body>

Note that this must be placed inline. It cannot be placed in an external javscript file!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.