Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

add Application.cfc and application level javascript

Community Beginner ,
Jan 16, 2024 Jan 16, 2024

I have a situation where my site uses a Application.cfc file for error trapping. This by itself works fine. I now have some JavaScript I need to add to the entire application so the default would be to add it to Application.cfm but of course I can't use Application.cfm and Application.cfc. 

Is there a way to add the JavaScript at the Application level either in Application.cfc or some other way?

257
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2024 Jan 16, 2024

You can use the onrequeststart method of application.cfc to perform the same things you would have done on a per-request basis in application.cfm., (Don't confuse that with onrequest, which works differently, for those desiring to add front-controller logic to their app..)

 

Check out any of many available online resources introducing application.cfc, which while it came out with CF7 about 20 yrs ago is still something that many developers find to be new to them--and many code bases still have not been converted to use it. 


/Charlie (troubleshooter, carehart. org)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 16, 2024 Jan 16, 2024

Thanks for your response. I guess I didn't post my question the right way but your reponse helped define it. Here is my expanded question.

As shown below, calling page2 can be done in 3 different ways. Our objective is to allow all 3 ways on some pages, but limit to a Form.Submit on others. We have found a lot of errors occurring due to Cyber Attack and search bots hitting our pages (Page2) directly.

The solution I am working on would require a call to a function (checkifValidCall()) to check if we want them to continue or to abort from an Application level. The check first checks to see if we want to check by setting parameter CheckCall=1. If set then the CheckIfValidCall() checks checks if Form.submit is defined. If it is then it returns and processing continues. If not then abort.

Page 1:

Href ”Page2 url?...”

                Or

URL typed in search bar

                Or

Form.submit

 

Page 2:

                Set CheckCall = 1    if page is to be checked

                Call checkIfValidCall() – this needs to be accomplished at Application level

 

Application Level:

                checkIfValidCall()

  • If CheckCall is defined then
    • If form.submit is defined
      • Continue
    • Else
      • Log and abort
    • Else
      • Continue

 

 

All this works if the functions are in an include file but I would like to move the code to the application level and can’t seem to get it to work.

 

Bottom line is it needs to set a parameter and then have the code run. I looked at onrequeststart but it happens before I can set a parameter on the page. Any suggestions would be helpful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2024 Apr 03, 2024
LATEST

The requirements of the problem are confusing. You don't want the visitor hitting page 2 directly. Yet page 2 has to run to set CheckCall = 1 and to call checkIfValidCall(), which the application requires in order to determine whether page 2 should run. Do you see that this amounts to a chicken-and-egg conundrum?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources