Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To SAVE or to COMMIT 1

Status
Not open for further replies.

TudorSmith

Programmer
Jan 14, 2002
245
GB
I have an ASP page with several input text boxes (Typically holding numerical values)

At the end of the form I have two SUBMIT buttons:
Code:
<form method="POST" action="AddPhasedBudget.asp" name="form1">

Blah Blah Blah <INPUT FILES HERE>

<input name="save" type="submit" value="Save Record">
<input name="Commit" type="submit" value="Commit Record">
</form>

My objective is if the user clicks <SAVE RECORD>, then the data is passed to the table and saved (I have this code in place and it works fine). What I have though is a field called "Commited" in the table, and if the user clicks <COMMIT RECORD> instead of just saving the entry, the flag in the table will be set. this will mean it will return "Read Only" every time a user retrieves the saved record (i.e. cannot edit if "Commit" = true)

My task..and I can't work it out because I'm a novice ASP programmer..is how do I tell the form to pass save the record on one button and to commit the record on another button!

Any ideas?

Thanks

Tudor

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
simple solution

change them to buttons and use a bit of javascript with a hidden field

while submitting to the same page
<script language="javascript">
function catchBut(str) {
if(str=="committed") {
form1.hiddenfld.value = "committed";
form1.submit();
}
if(str=="save") {
form1.hiddenfld.value = "save";
form1.submit();
}
}
</script>
<form method="POST" action="AddPhasedBudget.asp" name="form1">

Blah Blah Blah <INPUT FILES HERE>

<inptu type="hidden" name="hiddenfld">
<input name="save" type="button" value="Save Record" onClick="catchBut('save');">
<input name="Commit" type="button" value="Commit Record" onClick="catchBut('committed');">
</form>

then server.transfer on the condition found when loading the page
<html>
<%
If Request.Form("hiddenfld") = "committed" Then
server.transfer "some page to process commit"
ElseIf Request.Form(hiddenfld") = "save" Then
server.transfer "somewhere else for save"
Else

...load form...

End If
%>

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page faq333-3811
 
wow...that looks cool! I can't wait to test it at work tomorrow (IIS doesn't want to work on my XP machine at home!)

One thing though...I'm confused about the last bit

Code:
then server.transfer on the condition found when loading the page
<html>
<%
If Request.Form("hiddenfld") = "committed" Then
  server.transfer "some page to process commit"
ElseIf Request.Form(hiddenfld") = "save" Then
  server.transfer "somewhere else for save"
Else
 
...load form...

End If
%>

Is this bit of code in the new form or the same form?

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
same form.

here's a example of the process in all

say you have a page named page1.asp

in this page you have the form with two options of save or commit. in your needs those events have the two different options. what I have always found to be a simple and easy to maintain process is keep all that logic and need in that one page. hence th button repalcement with a dynamic submit. What may be a bit confusing is the Server.Transfer portion. Server.Transfer will transfer the form collection to the next page. normally what happens is the form collection is killed (cleared) after it hits the next load.

so say page1.asp has entire in it
Code:
<html>
<%
If Request.Form("hiddenfld") = "committed" Then
  server.transfer "page2.asp"
ElseIf Request.Form("hiddenfld") = "save" Then
  server.transfer "page3.asp"
Else
%>
<head>
<script language="javascript">
function catchBut(str) {
if(str=="committed") {
  form1.hiddenfld.value = "committed";
  form1.submit();
  }
if(str=="save") {
  form1.hiddenfld.value = "save";
  form1.submit();
  }
}
</script>

</head>
<body>

<form method="POST" action="page1.asp" name="form1">
<input type="text" name="txt" value="my text">
<input type="hidden" name="hiddenfld">
<input name="save" type="button" value="Save Record" onClick="catchBut('save');">
<input name="Commit" type="button" value="Commit Record" onClick="catchBut('committed');">
</form>
</body>
<%
End If
%>
</html>

what's going to happen is the form is submitted but prior to sending teh colelction over it sets the needed value to the hidden field.

Then in this bit
Code:
<%
If Request.Form("hiddenfld") = "committed" Then
  server.transfer "page2.asp"
ElseIf Request.Form("hiddenfld") = "save" Then
  server.transfer "page3.asp"
Else
%>
it catches which value is there and redirects to the conditioned page.

then if you have the two pages set as page2.asp, page3.asp coded as such
Code:
page2.asp
<%
Response.Write Request.Form("txt") & " Was committed!"
%>

page3.asp
<%
Response.Write Request.Form("txt") & " Was saved!"
%>

if the value was set to saved you'll output in the final stage
my text Was saved!

here's a bit from devguru on the Server.Transfer
devguru said:
Transfer (Path) Method Implemented in version 3.0
The Transfer method allows you to transfer all of the state information for all of the built-in objects from one ASP page to another. Unlike the Execute method, when the ASP page that you have transferred to is finished, you do not return the original ASP page.

Server.Transfer

hope that helps explain it

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page faq333-3811
 
Top notch! Thank you!

birklea ~©¿©~ <><
Dim objJedi as Jedi.Knight
Set objJedi[skyWalker].Aniken = FatherOf(useThe.Force(objJedi[skyWalker].luke))
 
Another option would have been to look at the value of the commit button on the processing page:
Code:
If Request.Form("commit") <> "" Then
   commit_var = true
Else
   commit_var = False
End If
Then use that var to enter the value for the commit field while your submitting the record.

I have to admit I usually go with the javascript way also, this never occurs to me until after I have written the javascript :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top