• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Cookie Monster

I would like to have a form on my web page where there is two fields;  NAME and COMPANY.  The user will press SUBMIT and the values they type in for these fields will be stored on their computer.

After they have hit submit and the cookie has been stored I want to put them into a new ORDER ENTRY form that will contain their NAME and COMPANY in two fields.  From this point forward when they perform activities I will have these two values that I will be able to FLAG to all their transactions.

Can anybody help with doing this?  I have successfully created cookies before but never based upon a value that they type... my cookies have always been hard-coded values.  Plus I have set the cookie in the $$HTMLHeader which I believe sets the cookie upon LOADING instead of when the user submits the form.

Can anybody help?  Thanks!
2 Solutions
Is there any need to submit the form?  You can use Javascript to set the cookie, and once the cookie is set, the Javascript can navigate to your order entry form!

Actually, I think a better way to do it would be to set the two fields to be editable, based on a cookie.  When the user submits, the result page should set the cookie to whatever was submitted.

The way this works is not terribly complicated.  Your $$Return or WebQuerySave redirects to a URL.  Append the cookie values to the URL.  The HTML head stuff can set the cookie based on this URL.  if the URL is another order entry form, you may also need to program the default values to look at the query string before looking at the cookie, because Domino will, I think, be evaluating based on the old cookie value that was sent with the URL request, not the new one being set via the URL.

An alternative: Have your onSubmit code set the cookie to whatever is currently in the fields.  Do not put in a default formula at all.  Have your onLoad take the current cookie values and place them in the HTML fields.  All the cookie code will then be on the client side.
Sno, It is easier to retrieve cookie value. Create a field Called HTTP_Cookie, computed with "" as value.

This will extract any cookie stored in local machine for the site and path it was stored against.

Sno, What hemanth has mentioned holds good for session based cookie, You can easily get the value of the Cookie from HTTP_Cookie, but when the session gets closed, still u want it to be done, then you can think abt storing information related to his IP address and the information.. Something like his ip address, and the values .. which u can compare and display anytime

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

snocrossAuthor Commented:
Ok so far I have a logon form with an $$HTMLHead field with the following formula;

"<META HTTP-EQUIV=\"Set-cookie\" CONTENT=\"FirstName=PatrickLastName=BachmannCompany=Barber FoodsEnd=;path=/;expires=Saturday, 031-Dec-05 12:00:00 GMT;\">"

Now on this same form I have a NAME field and a COMPANY field that pull in the information from the cookie by referencing the HTTP_Cookie field;

@Middle(HTTP_Cookie;"FirstName=";"LastName=")+" "+@Middle(HTTP_Cookie;"LastName=";"Company=")


Ok life is good at this point... the fields default to my hardcoded name and company however now I want them to be able to type any name and company they choose and the cookie code to reference these two fields.  

1) How can I do this?
2) If I do this in the $$HTMLHead field then won't it execute BEFORE the new values are entered?  Don't I need to set the cookie somehow AFTER they have typed the values?  Is this where I should simply pass the values in the URL to a second form that will then set the cookie upon loading?
You have to use methods of JS to write cookies while submitting the form or during exit event of the fields ?? Need Code ???
snocrossAuthor Commented:
But I almost have it!  I'm now have a LOGIN button and it passes the values to a second form in the URL.  The second form sets the new cookie to be the same as the values passed in the URL however the second form doesn't display the new cookie until I REFRESH it.  Seems the HTTP_Cookie field is not evaluating until RESAVED.  It seems to be happening in this order on the second form;

1) HTTP_Cookie Gets current cookie (Retreives old cookie)
2) $$HTMLHead Sets new cookie from URL

It happens in this order even though the $$HTMLHead field is FIRST on my form!!
Yes that is the way it evaluates.. In your case you have to set cookie before going to the next form.. That would be during onLoad event of the document
snocrossAuthor Commented:
Ok I think I have solved it by using a third form!  Ugly but it works.  Now the problem will be preventing users from BOOKMARKING a page and bypassing these forms.  Maybe somehow if the user is ANONYMOUS and a cookie is not found then force them back to the LOGIN screen?
In the onLoad even of the form.. paste this code

if( document.forms[0].HTTP_Cookie.value == "") {
alert("No Login information found" )
location.replace( "url redirection goes here " );


Also enable generate html for all fields, so that if http_cookie is computed and hidden it is available for the Javascript.
snocrossAuthor Commented:
Ok thanks... will award points soon...
snocrossAuthor Commented:
Thanks everyone!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now