SUBROUTINE SETCOOKIE
* Validate contents of a simple form.
* If the contents are invalid, save the invalid data in a cookie
* and redisplay the original form.
* Otherwise, display the data entered for checking.

* Include the RealWeb definitions.
INCLUDE #RW.INCLUDE.DEFS FROM /SYSFILES/REALWEB,BP

EQU AM TO CHAR(254)

* Get the form data.
DATA = ""
CALL RW_GET_PARAM("NAME", DATA)

* Check that the data doesn't contain any numeric characters.
VALID = 1
FOR I = 1 TO LEN(DATA)
IF DATA[I, 1] >= "0" AND DATA[I, 1] <= "9" THEN VALID = 0
UNTIL VALID = 0
NEXT I

* If valid...
IF VALID = 1 THEN
* Delete any cookie.
CALL RW_SET_COOKIE("CookieForm", "", 0, "", "", "")

* Display the data entered for checking.
CALL RW_START_HTML_PAGE("Cookie Check", "", "", "", "")

CALL RW_START_PARA("", "")
CALL RW_PUT("Welcome, " : DATA)
CALL RW_END_PARA

CALL RW_END_PAGE

* Otherwise...
END ELSE
* Save the data in a cookie.
* Because we are calling GETCOOKIE directly from this
* subroutine, we need to ensure that the cookie is saved
* immediately.
CALL RW_SET_COOKIE_IMM("CookieForm", DATA, "", "", "", "")

* Call the GETCOOKIE subroutine.
CALL GETCOOKIE
END
RETURN