Session help

P

Paul M

Hi
What is considered too much to put into a session object. I have a contact
form in which I have set up a session object which stores the comments
field when the form is submitted, if the form is submitted again the
session is compared to the comments form field and if they are the same it
Response.writes "The information has already been sent"
Thanks
Paul M
 
T

Thomas A. Rowe

First, are doing this so that a user can submit, and then edit and submit again?

--
==============================================
Thomas A. Rowe
Microsoft MVP - FrontPage

http://www.Ecom-Data.com
==============================================
 
M

Mark Fitzpatrick

Paul,
Do you want them to only submit once per session no matter what they put in?
You could just a 1 as a session count to let you know it was submitted once
before. Another possibility, since you're comparing the comments field to
see if it's submitted twice, instead of comparing the full text you could,
instead, compare the length. It's not as accurate, but the chances of them
submitting text of the same exact length without a number of other items
also being the same are real small. This would let you only store a number
instead of the full text.
 
P

Paul M

Hi Mark
No I want them to be able to submit more info if they wish without having to
close the session by closing the browser or waiting for time out
Your idea of a count sounds good. How do you count the text field length ?
Thanks
Paul M
 
M

Mark Fitzpatrick

Are you using ASP or ASP.Net?

If classic ASP, then VBScript has a function called Len() that will take any
string, such as the text of the comment box, and return a number that
represents the number characters in it. Here's an example of it being used
in a client-side script: http://www.w3schools.com/vbscript/func_len.asp

If it's ASP.Net, any string variable has a Length property that will return
the number of characters. Sometimes you will need to first call the
ToString() method to ensure it's a string value and then call the length
such as myvariable.ToString().Length

Be sure to check and make sure the comment box isn't empty first as the
functions can blow up sometimes when trying to measure an empty string.
 
P

Paul M

Hi
I Must be doing something wrong because I can't get it to write as a Len

The code below works fine but it stores the full form field text instead of
a number I have tried several applications of the Len function but I get
out of range errors

This part writes the session when the form is submited


Response.write "Message sent successfully!"

Session("xsubmited")= Request.Form("xcomments")


and this checks the session against a form field if the user presses the
submit button again

if Session("xsubmited")= xcomments then
Response.Write " The form has already been submited"
Else


Thanks
Paul M
 
R

Ronx

Try this:

'remove leading and trailing spaces, and convert a Null to an empty
string
xcomments = trim(Request.Form("xcomments") & "")

if xcomments <>"" then
if Session("xsubmited") = len(xcomments) then
Response.Write " The form has already been submitted"
Else
Response.write "Message sent successfully!"
Session("xsubmited")= len(xcomments)
End if
Else
response.write "Comments field empty"
'error - comments field is empty
End if



--
Ron Symonds - Microsoft MVP (FrontPage)
Reply only to group - emails will be deleted unread.

http://www.rxs-enterprises.org/fp
 
P

Paul M

Thanks Ron
I could never have worked this one out. Just when you think you can get by
there is still loads to learn

Paul M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top