Forum Moderators: open

Message Too Old, No Replies

OK Cancel Message

OK Cancel Message

         

cbrink

11:32 am on Jun 22, 2007 (gmt 0)

10+ Year Member



Hi everyone!
I have the following script in submit.php asking the user to verify form details before I write it to the database or to cancel and change the form details in which case I just use history(-1) to go back. My problem is when I cancel it goes back to the form but still runs through the rest of the php code thus entering the wrong information to the database.
Any suggestions how to completely break and go back?

php variable declaration code ends here.
?>
<html>
<head>
<script language="JavaScript">
<!-- Begin
var agree=confirm("Check to confirm correctness. CANCEL to go back.\nCourse = <? echo "$coursename";?>");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</script>
</head>
<body>
</body>
</html>

<? php code starts to make connection etc.

colandy

11:46 am on Jun 22, 2007 (gmt 0)

10+ Year Member



Having typed you code in, and set the PHP variable $courseware, I get no issues with this at all. I would suggest that you try:

document.write(agree);

after the Confirm request, then if this returns what you expect. use document.write(agree) within the if statement to ensure that it's not the If statement that's causing you an issue. But from the code you've entered above, all appears fine.

PS - This was tested on IE7 so unless this is a browser specific issue the above holds true.

Bernard Marx

3:57 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I really don't think this is the way to do something like this.

The PHP is executing on the server. It is totally ignorant of the user's interaction with the client-side script. The PHP has already executed.

LifeinAsia

4:29 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You can do this, but you need to put it on the page where the user enters data, not on the the following page that processes the form. Use something like this

<script language="JavaScript">
<!-- Begin
function formconfirm() {
return confirm("Check to confirm correctness. CANCEL to go back.\nCourse = <? echo "$coursename";?>");
}
// End -->
</script>

<form action="whatever.php" onSubmit="return formconfirm()">
...
</form>

cbrink

6:03 pm on Jun 23, 2007 (gmt 0)

10+ Year Member



Thanks for the replies, got it working correctly.