I have been handed a project from a colleague who has now left the company which has a problem moving between forms. It is a php file that contains two forms and decides which one to display based on the contents of a hidden form variable. Form 1 is basically an order entry form and form 2 a confirmation screen before accepting the order. There is a back button on form 2 to return to the order entry form if the order cannot be accepted.
The problem is that the hidden form variables appear to only ever be set once and subsequent assignments to the form fields using Javascript do not appear to be accepted when the page reloads itself and decides what to display. Is there a way of defining a variable so that it can only ever be set once and never changed?
I’ve posted a sample of the type of code below – annoyingly this snippet works correctly but hopefully will demonstrate the concept. The real code is too big to post and calls in various other files.
In the real code the alert in Back_Click shows the form variable accepted being set to ‘NO’ correctly but when the page reloads the php variable $accepted still contains ‘YES’. Is it possible that the form variable is not related to the $php variable even though they share the same name? Possibly a server setting or a setting elsewhere in the other code files?
Thanks for any help….
Regards
Nick
<html>
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function Back_Click()
{
document.formconfirm.accepted.value = ‘NO’;
alert(document.formconfirm.accepted.value);
document.formconfirm.submit();
}
function Continue_Click()
{
document.formenter.accepted.value = ‘YES’;
document.formenter.submit();
}
–>
</script>
<head>Test File</head>
<body>
<?php
echo $accepted;
echo $YourName;
?>
<?php if ($accepted == ‘NO’ || !isset($accepted)) { ?>
<P>
Enter Form
<P>
<FORM action=”<?= $PHP_SELF ?>” method=”post” name=”formenter” id=”formenter”>
<INPUT name=”YourName” id=”YourName” type=”text” value=””>
<INPUT name=”accepted” id=”accepted” type=”hidden”>
</FORM>
<INPUT type=”button” name=”Continue” id=”Continue” onclick=”Continue_Click()” VALUE=”Continue”>
<?php } ?>
<?php if ($accepted == ‘YES’) { ?>
<P>
Confirm Form
<P>
<FORM action=”<?= $PHP_SELF ?>” method=”post” name=”formconfirm” id=”formconfirm”>
<INPUT name=”YourName” id=”YourName” type=”text” value=””>
<INPUT name=”accepted” id=”accepted” type=”hidden”>
</FORM>
<INPUT type=”button” name=”Confirm” id=”Confirm” VALUE=”Confirm”>
<INPUT type=”button” name=”Back” id=”Back” onclick=”Back_Click()” VALUE=”Back”>
<?php } ?>
</body>
</html>