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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

previewing a page before submission

Status
Not open for further replies.

chinedu

Technical User
Mar 7, 2002
241
US
I am pretty sure I am doing something wrong; just can't figure it out.
I have 3 pages.
Page one inputs data into a form and submits the form.
As soon as the form is submitted, it goes to page2 where data entered is previewed.
If everything is fine, data is then submitted to the db.
if not, then you are taken back to page1 for editing and resubmission.
Having page 3 is not working.
So I removed page3 and made it just 2 pages.
It is still not working.
When I click the take me back button, it works but when I click the submit button, it does not submit to the database.
Can someone please take a look at page2 and advise me of what is wrong?
Thanks in advance.
<html>
<head>
<title>View Before Submitting</title>
</head>
<body>

<%@ language=vbscript%>
<%Response.buffer=true%>
<%
dim txtSpecName,txtOfferName,txtmakeModel,txtAlternatemakemodel,txtcontactName,txtContactEmail,txtItemDesc
txtSpecname = request.form(&quot;txtSpecname&quot;)
txtOfferName = request.form(&quot;txtOffername&quot;)
txtMakeModel = request.form(&quot;txtMakeModel&quot;)
txtAlternateMakeModel = request.form(&quot;txtAlternateModel&quot;)
txtContactName = request.form(&quot;txtContactName&quot;)
txtContactEmail = request.form(&quot;txtContactEmail&quot;)
txtItemDesc = request.form(&quot;txtItemDesc&quot;)
catG = request.form(&quot;catG&quot;)

%>

<table width=400 border=0>
<tr>
<td width=400>
<font face=&quot;arial&quot; size=2>
<br>Here is the information you're submitting. If you would like to
make changes, please use the appropriate button below, or use the other
button to submit this entry as it is.
<br>
<br><b>Spec Name:</b> <%= txtSpecName %>
<br><b>Offer Name: </b> <%= txtOfferName %>
<br><b>Make & Model: </b> <%= txtMakeModel %>
<br><b>Alternate Make & Model: </b> <%= txtAlternateMakeModel %>
<br><b>Contact Name: </b> <%= txtContactName %>
<br><b>Contact Email: </b> <%= txtContactEmail %>
<br><b>Category: </b> <%= catG %>
<br><b>Specification: </b> <%= txtItemDesc %>

<form action=&quot;pageBeforeLast.asp&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;txtSpecName&quot; value=&quot;<%= SpecName %>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtOfferName&quot; value=&quot;<%= OfferName %>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtMakeModel&quot; value=&quot;<%= MakeModel%>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtAlternateModel&quot; value=&quot;<%= AlternateMakeModel %>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtContactName&quot; value=&quot;<%= ContactName %>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtContactEmail&quot; value=&quot;<%= ContactEmail %>&quot;>
<input type=&quot;hidden&quot; name=&quot;catG&quot; value=&quot;<%= CategoryID %>&quot;>
<input type=&quot;hidden&quot; name=&quot;txtItemDesc&quot; value=&quot;<%= ItemDesc %>&quot;>
<input type=&quot;submit&quot; value=&quot;Yes, Submit it!&quot;>&nbsp;
<input type=&quot;button&quot; value=&quot;Let's Try Again&quot; onClick=&quot;history.go(-1)&quot;>
</form></font>
</td>
</tr>
</table>

</body>
</html>
 
Your pages are unclear. From your intial post I assumed your goal was to have:
Page1 = The Form
Page2 = The Verification Page
Page3 = The Store in Database Page
If this is the case, then that form can't send the user back to Page1 if he's ready to submit it: Page1 doesn't know how to store data in a database, it's only a form. You need to send the user to Page3 with all of those hidden fields, whichever page will actually open a connection to the database and insert the data.
 
hi Genimuse!
As I indicated in my original post, I was going to use 3 pages - page1 form, page2 verification and page3 for submission but I was having problem getting all to submit via page3.

**************************************
Page1 doesn't know how to store data in a database
*************************************
This code: <input type=&quot;button&quot; value=&quot;Let's Try Again&quot; onClick=&quot;history.go(-1)&quot;>, actually sends you back to page1 although, I must admit there is a better more efficient way.

Will page3 have everything that page1 plus the hidden data from page2?
I have done this before and know how to write a code that will preview before submission but page1 is tricky.
I can post it if anyone wants to see it. It is about 350 pages but could have been longer if I hadn't written it the way I did.
I guess that is the trade-off.
 
When the user hits the &quot;Yes, Submit&quot; button, does it ever get to pageBeforeLast.asp? This is presumably your intended page 3 since it's what you have for the action=... on the hiddden form.

If control passes to this page, then do the request.form variables have values or not?

If they do, then do you build a SQL insert string or use a command object? What fails exactly?
 
There are two buttons on page1.
The first button is an 'Add' button and the other is 'Process' button.
The 'Add' button, when clicked, adds new text box for inputing data.
When all data is entered and you press the 'process' button, it submits data to page2 (pageBeforeLast.asp).
so request.form has values except this one:
<input type=&quot;hidden&quot; name=&quot;txtItemDesc&quot; value=&quot;<%= ItemDesc %>&quot;>
I will worry about this letter.
When you click ' <input type=&quot;button&quot; value=&quot;Let's Try Again&quot; onClick=&quot;history.go(-1)&quot;>', it takes you back as it should.
Now where problem comes in is when you pretend like everything is alright and you click the submit button,
everything on pageBeforelast.asp clears but nothing gets submitted to the database.
I was just wandering what I am missing on this page.
 
[tt]Stick to using two pages. If you're not creating session of the request.form(&quot;fields&quot;) you're not going to be able to carry them over to the third page.

1. First Page should submit to second page
2. Second page should receive entries and do insert. Then a the very bottom of page 2 you can re-direct back to first page or wheverever you whish...



Delete * from brain Where MaxLevel = &quot;Full&quot; and reaction = &quot;Slow&quot; order by StartOver
 
I think what you're missing is the idea that you need some page with the code to store the information in the database, whether it's part of Page2 or you put it on a third page.

Do you have the basic code for inserting the record to a database anywhere? Some place where you have code that creates a SQL statement that resembles:
Code:
SQL = &quot;INSERT INTO MyTableName (SpecName, OfferName, MakeModel) VALUES ('&quot; & txtSpecName & &quot;', '&quot; & txtOfferName & &quot;', '&quot; & txtMakeModel & &quot;')&quot;
(I just made those field names up, your table name would be whatever it's actually called, and the statement would be much longer to include all of your fields.)

I get the feeling from your posts that you don't have any code that opens a connection to the database, creates an insert statement like the example above, and executes it. If I'm right then you need to learn how to do that.

None of the FAQs here addresses it, so I did a quick Google search. I'm sure there are better pages than this one to explain it, but it's the first hit and it's not too bad:

 
I sincerely thank all of you for the response.
As I said before my good helpers, I have done this before.
I have written a code that inputs data into a form, creates a preview code and when everything is ok, submits to the database.
When I first wrote the code, I did it all in one page and it works fine.
This one that I am trying to do is giving a hard time due to the way the first page is written.
Please allow me to attach the first page for your viewing pleasure(?).
This first page called insertSpec.asp, was originally written based on the requirement that input text boxes must be dynamic.
In other words, a user has to copy a text from somewhere and paste it into the an input box and since the user has no idea how many times a text has to be copied and pasted, we must provide the user with the ability to copy, paste, click the 'Add' button to automatically open up another textbox.
Once he/she is done with copying and pasting, and is now ready to submit to db, then the user clicks the 'process' button to submit.
This was the original spec.
Now, the user comes back and says, we now need the ability to review what we are submitting before submitting it.
This is where the difficulty has come in.
I can't think of a way to make you see a demo but if you run this code on an access database, you will see what I am talking about.
I will try and create a link for you to see it tomorrow but here is the code for first page.

<%
'-----------------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------------
Function Display_EventInsert(strGrid)
%>
<html>
<head>
<title>Insert Justifications</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;ffffff&quot;>
<form name=&quot;Insert&quot; method=&quot;post&quot; action=&quot;InsertRequireMents.asp&quot;>
<p><center><b>FC <BR>DPW</b></center></p>
<div align=&quot;center&quot;>
<table width=&quot;88%&quot; border=&quot;1&quot; bordercolor=&quot;000000&quot;>
<tr>
<td>
<div align=&quot;left&quot;>
<table><tr><td><b>TITLE: SPECIFICATION FOR A </b></td><td>
<input name=&quot;txtSpecName&quot; type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;50&quot; value=&quot;<%=request.form(&quot;txtSpecName&quot;)%>&quot;>
</td><td><b>OR EQUAL.</b></td></tr></table>
</div>
<div align=&quot;left&quot;>
<table>
<tr>
<td>
<p>
</td>
</tr>
<br><br>
<tr>
<td><b>
**NOTE**
</b></td>
</tr>
<tr>
<td>
<b>THE</b>
</td>
<td>
<input name=&quot;txtOfferName&quot; type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;50&quot; value=&quot;<%=request.form(&quot;txtOfferName&quot;)%>&quot;>
</td>
<td>
<b>OFFERED SHALL BE</b>
</td>
</tr>
</table>
</div>
<p>
<b>COMPARABLE WITH THE DETAILED REQUIREMENTS LISTED BELOW<br>
UNLESS OTHERWISE NOTED. ALL BIDDERS SHALL INDICATED EXACTLY<br>
WHAT THEY ARE OFFERING IN THE FOLLOWING BLANKS UNDER<br>
&quot;BIDDERS RESPONSE&quot;. ALL EXCEMPTIONS TO NON COMPLYING<br>
DETAILED FEATURES MUST BE IDENTIFIED AND EXPLAINED
</b></p>

<div align=&quot;left&quot;>
<table>
<tr>
<td>
<b>MAKE & MODEL PROPOSED</b>
</td>
<td>
<input name=&quot;txtMakeModel&quot; type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;50&quot; value=&quot;<%=request.form(&quot;txtMakeModel&quot;)%>&quot;>
</td>
</tr>
<tr>
<td>
<b>ALTERNATE MAKE & MODEL PROPOSED</b>
</td>
<td>
<input name=&quot;txtAlternateModel&quot; type=&quot;text&quot; size=&quot;40&quot; maxlength=&quot;50&quot; value=&quot;<%=request.form(&quot;txtAlternateModel&quot;)%>&quot;>
</td>
</tr>
</table>
</div>
<br>
<div align=&quot;left&quot;>
<table>
<tr>
<td>
<font color=&quot;green&quot;><b>*&nbsp;All Vendors Must Mark &quot;Yes&quot; or &quot;No&quot; To Comply With Each Individual Specification Below.</b></font>
</td>
</tr>
</table>
</div>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>Specifications </td>
<td>Yes</td>
<td>No</td>
</tr>
<%response.write(strGrid)%>
</table>
<br>
<div align=&quot;left&quot;>
<table>
<tr>
<td>
<b>FOR ADDITIONAL INFORMATION PLEASE CONTACT</b>
</td>
</tr>
</table>
</div>
<div align=&quot;left&quot;>
<table>
<tr>
<td>
<input name=&quot;txtContactName&quot; type=&quot;text&quot; size=&quot;28&quot; maxlength=&quot;40&quot; value=&quot;<%=request.form(&quot;txtContactName&quot;)%>&quot;>
</td>
<td>
<b>AT</b>
</td>
<td>
<input name=&quot;txtContactEmail&quot; type=&quot;text&quot; size=&quot;28&quot; maxlength=&quot;40&quot; value=&quot;<%=request.form(&quot;txtContactEmail&quot;)%>&quot;>
</td>
</tr>
</table>
</div>
</table>
</div>
</form>
</body>
</html>
<%
End Function
'-----------------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------------
Function Build_PersonGrid(strGrid)
Dim intCount, x

If request.form(&quot;Count&quot;) = &quot;&quot; then
'set default number of lines in the grid, in this case 5(!)
intCount = 0
else
'retrieve current amount of lines in the grid, increment by 1
intCount = Cint(request.form(&quot;Count&quot;) + 1)
end if

For x = 0 To intCount
strGrid = strGrid & &quot;<tr>&quot; & vbNewLine
strGrid = strGrid & &quot;<td><input name=&quot;&quot;txtItemDesc&quot;&x&&quot;&quot;&quot; size=&quot;&quot;80&quot;&quot; type=&quot;&quot;text&quot;&quot; maxlength=&quot;&quot;400&quot;&quot; value=&quot;&quot;&quot;&request.form(&quot;txtItemDesc&quot;&x)&&quot;&quot;&quot;></td>&quot;& vbNewLine
strGrid = strGrid & &quot;<td><input name=&quot;&quot;txtYes&quot;&quot; TYPE=Text size=2 value=&quot;&quot;&quot;&request.form(&quot;txtYes&quot;&x)&&quot;&quot;&quot;></td>&quot;& vbNewLine
strGrid = strGrid & &quot;<td><input name=&quot;&quot;txtNo&quot;&quot; TYPE=Text size=2 value=&quot;&quot;&quot;&request.form(&quot;txtNo&quot;&x)&&quot;&quot;&quot;></td>&quot;& vbNewLine
strGrid = strGrid & &quot;<td>&quot;
strGrid = strGrid & &quot;</td>&quot;& vbNewLine
strGrid = strGrid & &quot;</tr>&quot;& vbNewLine
Next


'set new Count, and action
strGrid = strGrid & &quot;<tr><td>&quot;
strGrid = strGrid & &quot;<input type=&quot;&quot;hidden&quot;&quot; name=&quot;&quot;Count&quot;&quot; value=&quot;&quot;&quot;&intCount&&quot;&quot;&quot;>&quot;&vbNewLine
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_AddNewLine&quot;&quot; value=&quot;&quot;Add&quot;&quot;>&quot;& vbNewLine
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_Process&quot;&quot; value=&quot;&quot;Process&quot;&quot;>&quot;& vbNewLine
strGrid = strGrid & &quot;</tr></td>&quot;

Build_PersonGrid = strGrid
End Function
'-----------------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------------
Sub Process_InsertEvent()
Dim strSQL, intCount, x

intCount = request.form(&quot;Count&quot;)

'-----------------------------------------------------
'build ADODB.Connection here, should be called &quot;objConn&quot;
set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;dsn=spec&quot;
'-----------------------------------------------------
If request.form(&quot;txtSpecName&quot;) <> &quot;&quot; then
strSpecName = request.form(&quot;txtSpecName&quot;)
else
strSpecName = &quot;N/A&quot;
end if

If request.form(&quot;txtOfferName&quot;) <> &quot;&quot; then
strOfferName = request.form(&quot;txtOfferName&quot;)
else
strOfferName = &quot;N/A&quot;
end if

If request.form(&quot;txtMakeModel&quot;) <> &quot;&quot; then
strMakeModel = request.form(&quot;txtMakeModel&quot;)
else
strMakeModel = &quot;N/A&quot;
end if

If request.form(&quot;txtAlternateModel&quot;) <> &quot;&quot; then
strAlternateModel = request.form(&quot;txtAlternateModel&quot;)
else
strAlternateModel = &quot;N/A&quot;
end if

If request.form(&quot;txtContactName&quot;) <> &quot;&quot; then
strContactName = request.form(&quot;txtContactName&quot;)
else
strContactName = &quot;N/A&quot;
end if

If request.form(&quot;txtContactEmail&quot;) <> &quot;&quot; then
strContactEmail = request.form(&quot;txtContactEmail&quot;)
else
strContactEmail = &quot;N/A&quot;
end if

'insert the event data
strSQL = &quot;INSERT INTO tbl_Events( &quot;
strSQL = strSQL & &quot;SpecName, &quot;
strSQL = strSQL & &quot;OfferName, &quot;
strSQL = strSQL & &quot;MakeModel, &quot;
strSQL = strSQL & &quot;AlternateModel, &quot;
strSQL = strSQL & &quot;ContactName, &quot;
strSQL = strSQL & &quot;ContactEmail) &quot;
strSQL = strSQL & &quot;VALUES(&quot;
strSQL = strSQL & &quot;'&quot;&strSpecName&&quot;', &quot;
strSQL = strSQL & &quot;'&quot;&strOfferName&&quot;', &quot;
strSQL = strSQL & &quot;'&quot;&strMakeModel&&quot;', &quot;
strSQL = strSQL & &quot;'&quot;&strAlternateModel&&quot;', &quot;
strSQL = strSQL & &quot;'&quot;&strContactName&&quot;', &quot;
strSQL = strSQL & &quot;'&quot;&strContactEmail&&quot;')&quot;
'response.write(strSQL)
response.write(&quot;<p>&quot;)
objConn.execute(strSQL)

strSQL = &quot;SELECT MAX(EventID) AS NewEvent FROM tbl_Events&quot;
'response.write(strSQL)
response.write(&quot;<p>&quot;)
set rsData = objConn.execute(strSQL)

intNewEventID = rsData(&quot;NewEvent&quot;)

rsData.close
set rsData = nothing

'insert the Item Descriptions, from grid
For x = 0 To intCount
If request.form(&quot;txtItemDesc&quot;&x) <> &quot;&quot; then
strItemDesc = request.form(&quot;txtItemDesc&quot;&x)
else
strItemDesc = &quot;N/A&quot;
end if

If request.form(&quot;txtYes&quot;&x) <> &quot;&quot; then
strYes = request.form(&quot;txtYes&quot;&x)
else
strYes = &quot; &quot;
end if
If request.form(&quot;txtNo&quot;&x) <> &quot;&quot; then
strNo = request.form(&quot;txtNo&quot;&x)
else
strNo = &quot; &quot;
end if

strSQL = &quot;INSERT INTO tbl_Persons( &quot;
strSQL = strSQL & &quot;ItemDesc,&quot;
strSQL = strSQL & &quot;TheYes,&quot;
strSQL = strSQL & &quot;TheNo,&quot;
strSQL = strSQL & &quot;EventID) &quot;
strSQL = strSQL & &quot;VALUES( &quot;
strSQL = strSQL & &quot;'&quot;&strItemDesc&&quot;',&quot;
strSQL = strSQL & &quot;'&quot;&strYes&&quot;',&quot;
strSQL = strSQL & &quot;'&quot;&strNo&&quot;',&quot;
strSQL = strSQL & &quot;&quot;&intNewEventID&&quot;)&quot;
'response.write(strSQL)
'response.end
response.write(&quot;<br>&quot;)
objConn.execute(strSQL)

Next

objConn.close
set objConn = nothing

response.write(&quot;Action was a succes. All data was processed in database <br>&quot;)
response.write(&quot;<a href='InsertRequirements.asp'>Create Another Record</a>&quot;)

End Sub
'-----------------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------------
Sub Main
Dim intAction

If request.form(&quot;cmd_AddNewLine&quot;) <> &quot;&quot; then
intAction = Cint(0)
elseif request.form(&quot;cmd_Process&quot;) <> &quot;&quot; then
intAction = Cint(1)
Else
intAction = Cint(0)
end if

Select Case intAction
Case 0
strGrid = Build_PersonGrid(strTemp)
Display_EventInsert strGrid
Case 1
Process_InsertEvent
End Select
End Sub
'-----------------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------------
Call Main()
%>
 
sorry I was in a hurry to go to a meeting that I sent the wrong code.
Here is a few fixes to the one I sent.
On the head of that code, I added this javascript code:
<script language=&quot;javascript&quot;>
function ProcessSearch(strcatvalue)
{
alert(strcatvalue +&quot;1&quot;)
if(strcatvalue==&quot;Add&quot;)
{
strAction = &quot;InsertRequirements.asp&quot;
alert(strcatvalue+&quot;2&quot;)
}
alert(strcatvalue+&quot;3&quot;)
if(strcatvalue==&quot;Process&quot;)
{
strAction = &quot;pageBeforeLast.asp&quot;
alert(strcatvalue+&quot;4&quot;)
}
document.forms[0].action=strAction
document.forms[0].submit()
}
</script>

On the body,
I have this:
<body bgcolor=&quot;ffffff&quot;>
<form name=&quot;Insert&quot; method=&quot;post&quot;>

then instead of this:
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_AddNewLine&quot;&quot; value=&quot;&quot;Add&quot;&quot;>&quot;& vbNewLine
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_Process&quot;&quot; value=&quot;&quot;Process&quot;&quot;>&quot;& vbNewLine

I have this:
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_AddNewLine&quot;&quot; value=&quot;&quot;Add&quot;&quot; onClick=&quot;&quot;ProcessSearch('Add')&quot;&quot;>&quot;& vbNewLine
strGrid = strGrid & &quot;<input type=&quot;&quot;submit&quot;&quot; name=&quot;&quot;cmd_Process&quot;&quot; value=&quot;&quot;Process&quot;&quot; onClick=&quot;&quot;ProcessSearch('Process')&quot;&quot;>&quot;& vbNewLine

Essentially, I am saying if I click the 'Add' button, then add another textbox under specification.
but if I click 'Process', then send my data to the page to pageBeforeLast.asp
As I indicated, the only data that is not being sent to the pageBeforeLast is txtitemDesc.
i don't know why but I will worry about that after the preview and submit page is working.
Sorry about the long codes

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top