954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

prevent user from going back or disable submit

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.

itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

i'm using javascript

itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
i'm using javascript

javascript is for client side

anything for server side ?

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 
itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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

itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
saving it to a file using php..is that a scripting language?

yeah..... :)

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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>";
}
?>
itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 
aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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!!!

sureronald
Junior Poster
139 posts since May 2008
Reputation Points: 11
Solved Threads: 19
 

can i put php inside javascript?

itnagusak
Newbie Poster
12 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

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 ?

aashishn86
Junior Poster
188 posts since Jun 2008
Reputation Points: 10
Solved Threads: 9
 

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!!

sureronald
Junior Poster
139 posts since May 2008
Reputation Points: 11
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You