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

How to detect if the page is a reload or not?

Enthusiast ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

I have a form in the cfm page that if the user submit the form, I do not want to go to a different page. I want it to reload the page and I'll capture all the values and send the data that way. However, I need to hide the form once the user submitted the form. So, how do I detect if the page is a reload (after it's been submitted) or it's the first time it's been loaded?

Views

1.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Guide , Mar 17, 2016 Mar 17, 2016

You can handle that a couple of ways.  One, add a hidden field to the form that passes some value, then check if the value exists in URL/FORM variables (if it exists, page was reloaded by form submit - if it doesn't exists, this is the first load of page).

Perhaps a better approach would be to handle the form submittal via an AJAX request, then hide the form if the AJAX request is successful.  This can all be accomplished using JavaScript.  The advantage is that the user never actually leaves the

...

Votes

Translate

Translate
Guide ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

You can handle that a couple of ways.  One, add a hidden field to the form that passes some value, then check if the value exists in URL/FORM variables (if it exists, page was reloaded by form submit - if it doesn't exists, this is the first load of page).

Perhaps a better approach would be to handle the form submittal via an AJAX request, then hide the form if the AJAX request is successful.  This can all be accomplished using JavaScript.  The advantage is that the user never actually leaves the page or reloads it.

Votes

Translate

Translate

Report

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
Enthusiast ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

Thanks, Carl! I guess give AJAX a try. The thing is, I need to capture all the values in the form and do a cfhttp post to a jsonp api in the same cfm page. So, I'm not sure if AJAX is the proper way to do it.

Votes

Translate

Translate

Report

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
Guide ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

I need to capture all the values in the form and do a cfhttp post to a jsonp api in the same cfm page

Maybe you can elaborate on the reasons this exact process is required.  Why can't you make an AJAX request directly to the jsonp API?  Why the need for CFHTTP post?

Votes

Translate

Translate

Report

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
Enthusiast ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

I do not point to expose my API key to public. That is why I was thinking of using cfhttp for sending the json data over.

Votes

Translate

Translate

Report

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
Guide ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

That makes sense.  Did that come up in a previous thread on the forum?  Sounds vaguely familiar.

Votes

Translate

Translate

Report

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
Enthusiast ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

LATEST

Yes, it is familiar with my other thread when I tried to retrieve json data from a third party REST service. In that thread I use a proxy to get my data because I do not want to expose my api key. In this thread, I'm posting data back to API.

Votes

Translate

Translate

Report

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
Documentation