Two Functions:ReadFormVariables and SendHiddenFormFields<% '=================================================== 'The Functions below were developed by Robert Collyer:- ASPwiz@hotmail.com ' 'These scripts will now make variables live well beyond the page scope and make the debugging 'process of passing variables between pages just a memory. 'All scripts are really flexible and work on form elements, querystrings and cookies. ' '==================================================== 'The first Funtion-'GetVariables(type1, type2)' can be used in place of the very common:- 'var1=request.form("var1") 'var2=request.form("var2") 'var3=request.form("var3") 'var4=request.form("var4") 'var5=request.form("var5") 'and likewise for reading in querystrings and cookies ' 'Taking FORMS as an example: 'You simply now just call the function, and all vbscript values are set to match those 'posted from a form. This sounds great, and it is but the vbscript variables are named 'identically to the form/querystring/cookie variable names (this is usually a good thing) 'If for example a form contained a text box that is named 'Surname', 'and after submitting the form, the following page called upon the 'GetVariables("form",0)' 'function, VBScript would now have access to a variable called Surname containing the value 'of whatever the user entered into the textbox. It will loop through ALL form variables, 'setting the VBScript equivelents. ' ' '=================================================== 'The Second Function-'SaveAsFormFields(type1, type2)' is very useful for those occasions where 'you need to read in all the form/querystring/cookie values, and include them within another form as 'hidden fields. Reasons to this could include multiple page forms and also when a user 'enters data incorrectly on a form, and you want to post the data back for editing, etc ' '=================================================== 'The Third Function-'SaveAsCookie(type1, type2) will pass the variables stated by type1 and type2 'to a cookie on the clients computer. You can retrieve this cookie and read the variables 'back in on another page using:- Call GetVariables("cookies",0)
'===================================================== 'Please email ASPwiz@hotmail.com with all feedback. (Including bugs if any) 'I do not require a mention if you use this code (Unless the source is published), it 'is supplied purely because 'I know how much of a pain in the arse the long way round is and I feel sorry for those 'who are non-the-wiser. Please feel free to distribute this as far and as wide as you like. 'This message will self destruct, etc...... '==================================================
'*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//** '================================================== ' Call the following function with: ' ' Call GetVariables("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' ' Alternatively the function may be called as follows: ' Call GetVariables("ALL", 0) calling the function in this way performs all three types. '==================================================== function GetVariables(type1,type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form TheString = Field & "=Request.Form(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies TheString = Field & "=Request.cookies(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.querystring TheString = Field & "=Request.querystring(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if END function
'*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**
'==================================================== ' Call the following function with: ' Call SaveAsFormFields("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' 'Lastly the function may be also be called as follows: 'Call SaveAsFormFields("ALL", 0) calling the function in this way performs all three types. '====================================================
function SaveAsFormFields (type1, type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.Form(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.cookies(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.Querystring TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.querystring(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if END function
'*//**//**//**//**//**//**//**//**//**//**//**//**//
'====================================================== ' Call the following function with: ' Call SaveAsCookie("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' 'Lastly the function may be also be called as follows: 'Call SaveAsCookie("ALL", 0) calling the function in this way performs all three types. '====================================================== function SaveAsCookie (type1, type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form Response.cookies(field)= Request.Form(Field) Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies Response.cookies(field)= Request.cookies(Field) Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.Querystring Response.cookies(field)= Request.querystring(Field) Next end if END function '*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//** ' TESTING THE CODE 'uncomment the code below to test the functions. 'Set up a form or something to call this page passing variables 'or manually pass querystring info when calling this page 'once the script is run, checking the resulting html source ' will reveal the result of the saveasformfields function 'try typing: formfunctions.asp?test1=testing&test2=numbers12345&test3=final-test 'into the browser. 'Uncomment below here ' 'call getvariables("all",0) 'call SaveAsFormFields("all",0) 'call SaveAsCookie("all",0) 'response.write vbcrlf & test1 & "<BR>" & test2 & "<BR>" & test3 & vbcrlf 'response.write "<BR><BR>Cookies<BR>-------<BR>" & vbcrlf 'for each item in request.cookies ' response.write(Request.cookies(item))&"<BR>" & vbcrlf 'next 'response.write "<B><BR>Click View...source to see where hidden form elements have been set.</b>" %> |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
| | | | Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
| | | | In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
| | | | Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
| | | | Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |