Click to See Complete Forum and Search --> : Previewing Page Before Submitting


simflex
06-11-2003, 08:53 AM
This is a bit tricky my dear gurus.
It is tricky because I can't quite explain it well without showing the code but then the code is almost 400 pages long.
So I will attempt to explain it but then please tell me how to proceed.
A client has a requirement for us to create a user agreement page.
As most of you, if not all of you, have gone to a site such as this forum that has rules of engagement.
for instance, you are required to read the rules and check the agree or disagree box.
These agreements can be 10 or more, or perhaps less.
So in our case, the client has decided to make their rules and regulations database-driven.
What they want to do is to copy each agreement and paste into a text box with a yes/no response.
If you want to proceed, you click yes, if not you click no.
Since we cannot determine how many agreements will be copied and pasted into textboxes, we decided to create the page in a way that add additional input text boxes dynamically.
You start with one input text box, you copy an agreement and paste into a text box, then you click the 'Add' button to create another input text box, then you copy another agreement and paste it into this input text box. The circle continues until all agreements are copied and pasted into input textboxes.
At this point, you can submit to the database by clicking the 'Process' button.
Now if you need to retrieve this information, all you need to do is reference it by id or name and all data that have been copied and pasted, be it one line or 200 lines are displayed based on id passed or name.
The code works great as explained.
The twist comes in when the client comes back and says they would like the code modified so that they can view data entered before submitting to the database.
So that means, an input form, preview form and validation form.
Normally, I know how to do this and have done it before but
because of the way the code was originally written, it is difficult to implement this new requirement and I can't think of any other way to rewrite the original code.

Question, can anyone please suggest a way this can be accomplished.
As I said, the code is long but I will be more than happy to provide to anyone who believes he/she can help.
Thanks in advance and I apologize for the long thread.

Ribeyed
06-11-2003, 12:32 PM
Hi Simflex,
i am willing to help you if you zip the code and DB and post here i will take a look.

simflex
06-11-2003, 04:07 PM
hi Ribeyed,
My sincere apology. I was wisked to offsite immediately following my post.
I am attaching two asp pages.
One is called InsertRequirements.asp and the other is called pageBeforeLast.asp.
The first page as I indicated earlier takes input, does validation and passes the info to second page called pageBeforeLast.asp.
The intent is for second page to verify that input is correct.
If correct, then submit to db. if not, go back to first page, make your corrections and resubmit.
Second page isn't working out due to the way first page is coded.
I have attached a db that has only 3 tables -cart, inventory and cats.
Cats contains category with data preloaded. pk is ID.
inventory is related to Cats by catID and cart is related to inventory by inventoryID and related to cats by itemID.
This relationship shouldn't change because it is part of my shopping cart program.
My shopping cart code works great based on this relationship; changing it will affect my cart program which may delay the delivery date.
Please do the best you can with the db that I have.
Please let me know if you have any additional questions.
I will attach what I can here and attach rest on subsequent page.I have the display pages. They work really well. If you need them for testing, please ask me to send them.
Thanks for your help.

simflex
06-11-2003, 04:12 PM
Here is a zip of the two pages.
Thanks again!
By the Ribeyed, I still owe you for the accident program.

simflex
06-11-2003, 04:19 PM
One mistake I made right away is that on InsertRequirements page,
replace these lines:

'set new Count, and action
strGrid = strGrid & "<tr><td>"
strGrid = strGrid & "<input type=""hidden"" name=""Count"" value="""&intCount&""">"&vbNewLine
strGrid = strGrid & "<input type=""submit"" name=""cmd_AddNewLine"" value=""Process"" onClick=""DetermineAction('Add')"">"& vbNewLine
strGrid = strGrid & "<input type=""submit"" name=""cmd_Process"" value=""Process"" onClick=""DetermineAction('Process')"">"& vbNewLine
strGrid = strGrid & "</tr></td>"

with these:

'set new Count, and action
strGrid = strGrid & "<tr><td>"
strGrid = strGrid & "<input type=""hidden"" name=""Count"" value="""&intCount&""">"&vbNewLine
strGrid = strGrid & "<input type=""submit"" name=""cmd_AddNewLine"" value=""Add"" onClick=""DetermineAction('Add')"">"& vbNewLine
strGrid = strGrid & "<input type=""submit"" name=""cmd_Process"" value=""Process"" onClick=""DetermineAction('Process')"">"& vbNewLine
strGrid = strGrid & "</tr></td>"


This is what happens when you copy and paste.

Ribeyed
06-11-2003, 06:37 PM
HI Simflex,
Well I had a long look at your pages and code, phew! Mmmm…not sure where to start to help you on this one. I understand what it is you need to do but I just can’t follow your code. I know you made clear you are too far into it to make any big changes and there isn’t much I can do apart from rewrite everything my own way. Sorry I don’t think I can be much help getting your code to do what you need it to do. I would help rewrite it if that’s what you decide. :(

simflex
06-11-2003, 07:39 PM
i Ribeyed,
I know it is not easy modifiying someone else's code but as I said in my earlier thread, I don't mind you or anyone else rewriting it at all.
I know that the difficulty I am having with making page2 do what I want it to do is because of the way page1 is written.
So Please feel free to rewrite.
The only thing I ask for (which I did ask for in my last thread) is that the database design not change.
If the database design changes, I will have to deal with 2 situations.
Situation one is having to modify/rewrite the shopping cart problem which is even longer than the code you are looking at now.
Second and perhaps more difficult is understanding and modifying yours, if I need to.
So if you can help me rewrite it and still keep the database design the way it is, I will appreciate it.
Please let me know what you think.
I would like to see a different code do the same thing mine is doing anyway.

Ribeyed
06-12-2003, 09:42 PM
Hi Simflex,
please find attached a zip with your 2 files. Major code changing done here to get round some of the tricky stuff. I tried to comment as much as possible, but it maybe be confusing because i had to play about with the code a bit to get it working. Very difficult to implement the requirements but I think I cracked it. Hope you don’t require very much changes because I can see this code being very changeable. If however you do require changes there’s a good chance it would need rewritten.

I am still confused as to what the pages are for maybe you can explain it a bit better?
I didn’t finish of the inserting the data to the database this is because I don’t understand where the data is to be stored. Do you need a new record in the cat or inventory table for each specification you are requesting?
Not sure why in your database you have a field for Yes and a field for No, surely a yes/no field would do for this?
Is each specification to be stored in the itemdesc field in the cat table?
That’s what’s confusing; does each item have more than one itemdesc which is actually the specification?
Anyway if you need help inserting the specifications into the database just ask and I will write the code. It will just be similar code to what I used for the specifications.
Have to go its getting late here.

simflex
06-13-2003, 09:08 AM
hi Ribeyed,
You have done class A job on this code just getting it to the point where it would actually display specifications once "Process" is clicked.
Very impressive.
Now to answer your questions, there are still some unresolved issues such as whethere or not the client needs all of the fields on the cart and inventory tables.
But those are easy problems that I can fit up somewhere in the insert statement.
This will become clear on Monday.

I am still confused as to what the pages are for maybe you can explain it a bit better?

The client has some partners of theirs that sell them products.
This client has a set of rules governing the purchase of products which makes sense since it will be paying for it.
So if you are an employee of this client, and you need to purchase items such as camera, camcorder etc, you go to one of their partners called PhotoInc.
Before selecting an item and putting in the basket, you are required to say "yes" or "no" to a series of agreements that are govern the purchase of a camera or camcorder.
The client decided that it is too much of a hassle for their users to have to search their partners sites and find what they are looking for, browse thru the agreement and check yes or no. They decided to make all agreements database-driven.
One of their employees will have to go to each site, copy the agreements into this page called Insertrequirements.asp and save it to the database.
If you the employee need to make a purchase, you will have to go the inventory database, search the item by name, pull the agreement, print it and manually check yes or no. ( I didn't explain this part originally because that is why my yes or no was written the way it was).
After agreeing to the rules, you can then go to the shopping area and use the shopping basket to make your purchases.
So the two pages you just put together means that once an employee copies and pastes these rules and regulations, he/she needs to preview information entered to ensure that they are correct. this should take them to pageBeforeLast.asp
If data pasted is correct, they will click yes to submit to the database.
If not, they will click "Let's try again" to go back to InsertRequirements.asp to make any changes that need to be made and resubmit.
Now your code is doing just fine except when you click "Let's try again", it doesn't take you back to original page.
It just says "Done!"
Plus it is not submitting to the database.
Currently, what needs to be submitting to the database are those fields we have on the insert statement.


Do you need a new record in the cat or inventory table for each specification you are requesting?
Not sure why in your database you have a field for Yes and a field for No, surely a yes/no field would do for this?
Is each specification to be stored in the itemdesc field in the cat table?
That’s what’s confusing; does each item have more than one itemdesc which is actually the specification?


Yes, as you can see from testing, if you click the "Add" button, you get a new input text box that allows you to copy and paste more agreements.
It is like saying for each item you are purchasing, there are x number of specifications (rules) governing it.
Not sure if I am answering your question but if you need my list.asp and display.asp pages, they will kind of explain why we have them the way we do.
To retrieve the records, all you need to do is this:

'retrieve inventory ID from GET header, and assign to internal variable
intInventID = CInt(request.querystring("ID"))

'first query ; selection of unique info, in this case from the inventory table
strSQL = "SELECT * FROM inventory WHERE ID="& intInventID
'response.write strsql
'response.end
'create recordset called rsEventData
Set rsEventData = my_conn.Execute (strSQL)

'if, for some reason, there's no data, this page cannot be executed
If rsEventData.EOF Then
'response.write("<script>")
response.write("There was no data found. Please check the ID you've posted.")
'response.write("</script>")
'close and destroy recordset
rsEventData.close
set rsEventData = nothing
'stop page from executing
response.End()
End If

'second query ; selection of all the extra information, in this case
'from the cart table
strSQL = "SELECT * FROM cart WHERE inventoryID="& intInventID
'response.write(strSQL)
Set rsPersonData = my_conn.Execute (strSQL)

this way, it doesn't matter how many specifications you enter, all will be displayed at once based on the relationship from both tables.
I will attempt to fix the two problems I alluded to earlier.
If you have time, please do same just as a backup.
Please advise if you still need more explanation.
The other thing we need to do is to put something like a line or <hr> so that we can show when one specification ends and another begins.
Great work Ribeyed!

simflex
06-13-2003, 02:37 PM
Ribeyed,
Based on the tests I have done so far, everything seems to be working the way we want it.
I have added a horizontal line so that we can tell when txtDesc ends and another begins.
Not it is like:
Specification:

dfjfjfdskjdsflkdsfkldsffd
__________________________
spdsjkdsfkfkijdfkjkldskjdsfkjdsfkjl
kdsfuidjdfjjjkjkkjklj;lk;;lk
___________________________
etc

I have also added an onlick event so that if a user needs to go back and make any changes, s/he can go back to original page to make the changes and resubmit.
Data is getting submitted into the db.
There is one problem!
ItemDesc is not inserting into the db.
For the life of me, I can't figure that out.
If you or anyone who has been following this can, please let us know.
Meanwhile, after that is fixed, then the first phase of what they asked me to do would have been done successfully.
For phase one, they want an insert page, a preview page and a submit page.
This would have taken care of that.
Then they want to have a shopping cart program that can select what has been inserted into the db, put as many as possible in the db and when done, checkout.
That is working well with your code.
All we need now is to have that single field which is the heart of the requirements spec to get inserted into the db.
Afer this is working, we will just have to wait till our meeting next week and go from there.

Ribeyed
06-13-2003, 09:02 PM
HI Simflex,
did the best i can with what information you give me so here it is :D

Ribeyed
06-13-2003, 09:03 PM
oops, got a habit doing that....here it is this time!

simflex
06-14-2003, 08:24 AM
hello Ribeyed,
First of all, I want to you to know how truly impressed I am with your talent.
I believe I can program but you definitely have demonstrated you can program better.
I am truly impressed.
So far, the code seems to do what I am been told to make it do.
It is taken input data, previews data to ensure no errors, has the ability to go back and make changes if needed and then submit to the database.
Those requirements have been met beautifully.
More importantly perhaps, I didn't have to make any changes to my shopping cart program.
Thanks a lot!
A few changes have been made by me.
First, ID from inventory is an autonumber. I had to remove it from the inventory insert statement.
Same is the case with Id from cart.
Cats table only stores category which is prepopulated.
You have that fine; inventory relates to Cats by catID, you also have that and cart table relates to inventory by inventoryID. It relates to Cats by itemID.
You have all of that fine.
What I had to change from remove ID from inventory insert statement as well as from cart insert statement.
So far, everything seems to be working well.
I added one line of code to each itemDesc because for some reason, any text that has a single quote, is causing an error.
Example of text with single quotes aare can't. didn't it's etc.
So I had to add this line of code:
text0= Replace(text0, "'", "''")
I did it from text0 to text9.
So far, it seems to have solved the problem.
Speaking of text0 to text9,
I noticed (and also from your comments within the code) that input boxes can only be extended to 10, no more than 10.
Now that is fine as long as I can add more to the code to extend it further.
I believe in my first thread, I indicated that the agreements that the user copies and pastes into these input text boxes can be 10 or more.
Infact they can go as far as 30.
It rarely gets to 30 but has been there before so as long as I can modify the code to allow for more than 10 input text boxes, I believe we will be fine.
All it does is make the code longer but who cares anyway as long as it does what they want it to do.
As this point, I can say confidently that I am ready to show what I have got to management what I have got and hopefully all additional questions that I have can be addressed by them.
Again, thanks for showing off your immense talent.

Ribeyed
06-14-2003, 01:01 PM
HI Simflex,
thanks for your kind comments they were much appreciated :D
I am sure you will be able to make the program extent to 30 and not stop at 10. You are correct about the code changing to 30 will add in loads of lines of code. I normally don't code like that, creating a seperate sql insert statement for each one of the 10, but working with what you gave me i didn't see any other way of doing it.
Remember to change the line that says "if countoftextarea > 9" to 29 then copy, paste and change to add code of 11 - 29 then you should be home dry.
Well hope everything goes will on Monday with your boss, good luck!

David