Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:40:56+00:00 2026-06-09T12:40:56+00:00

As input for a function I get a string scopename like FORM or COOKIE

  • 0

As input for a function I get a string scopename like FORM or COOKIE.
How can I access these top level scopes in a bracket notation?

I’m looking for something like:

var myScope = "FORM";
global[myScope];

Obviously that doesn’t work though 🙂

(I’m not looking for any kind of eval function, I’d rather switch through the string manually to get the right scope than an eval function…)

EDIT

Functionality is needed so I can call an easy/accessible function early on in a request to identify bad requests that are either sending the wrong kind of data or are just not sending the required data.

for example I’ll call the following function as early as possible in a request that needs the variables FORM.data1:numeric, FORM.data2:bit and COOKIE.data3:string:

<cfset require({
  "FORM" : {
    "data1":"numeric",
    "data2":"bit"
  },
  "COOKIE":{
    "data3":"string"
  } 
})>

I’m aware that the following might have been a bit easier:

<cfset require({
  "FORM.data1":"numeric",
  "FORM.data2":"bit",
  "COOKIE.data3":"string"
})>

and than just use isDefined but I need some more flexibility for other functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:40:56+00:00Added an answer on June 9, 2026 at 12:40 pm

    Well, the simplest solution is just to write it like this:

    <cfparam name="form.data1"   type="numeric" />
    <cfparam name="form.data2"   type="numeric" />
    <cfparam name="cookie.data3" type="string" />
    

    However, if you find that too verbose, you can use your existing data structure, like this:

    <cfset require({
      "FORM" : {
        "data1":"numeric",
        "data2":"bit"
      },
      "COOKIE":{
        "data3":"string"
      } 
    })>
    
    
    <cffunction name="require" returntype="void" output=false >
        <cfargument name="Scopes" type="Struct" required />
    
        <cfloop item="local.CurScope" collection=#Arguments.Scopes#>
            <cfloop item="local.CurVar" collection=#Arguments.Scopes[CurScope]#>
                <cfparam name="#CurScope#.#CurVar#" type="#Arguments.Scopes[CurScope][CurVar]#" />
            </cfloop>
        </cfloop>
    </cffunction>
    

    Alternatively, there’s an even simpler way of doing it than that:

    <cfset require
        ( "FORM.data1"   : "numeric"
        , "FORM.data2"   : "bit"
        , "COOKIE.data3" : "string"
        )>
    
    <cffunction name="require" returntype="void" output=false >
    
        <cfloop item="local.ArgName" collection=#Arguments#>
            <cfparam name="#ArgName#" type="#Arguments[ArgName]#" />
        </cfloop>
    
    </cffunction>
    

    You imply that you need the unscoped name for other functionality, in which case you simply do <cfset UnscopedName = ListRest(ArgName,'.') />

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get a generic input to my function. I tried interface IReport
Consider some function foo : def foo(input) input * 2 end How to get
Im using scala Map#get function, and for every accurate query it returns as Some[String]
Hi all I am using this function to get name's of the input fields
suppose I have a form: <form id=someform action=some.php method=get> <input type=text name=somename /> <input
I've been working my way through Python, but can't seem to get past string
I would like to make a function that break lines from a string. eg.:
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
If papply returns a function of less arity than an input function, is there
I have this event listener: input_1.addEventListener('input',function(){ updateFromInput(1); },false); It controls the location of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.