Highlighted

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

Engaged ,
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?

Most Valuable Participant
Correct answer by Carl_Von_Stetten | Most Valuable Participant

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.

Views

635

Likes

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

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

Engaged ,
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?

Most Valuable Participant
Correct answer by Carl_Von_Stetten | Most Valuable Participant

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.

Views

636

Likes

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
Mar 17, 2016 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Mar 17, 2016 0
Engaged ,
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.

Likes

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
Reply
Loading...
Mar 17, 2016 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Mar 17, 2016 0
Engaged ,
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.

Likes

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
Reply
Loading...
Mar 17, 2016 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Mar 17, 2016 0
2Charlie LATEST
Engaged ,
Mar 17, 2016

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Mar 17, 2016 0