Skip to main content
2Charlie
Inspiring
March 17, 2016
Answered

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

  • March 17, 2016
  • 1 reply
  • 2088 views

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?

    This topic has been closed for replies.
    Correct answer Carl Von Stetten

    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.

    1 reply

    Carl Von Stetten
    Carl Von StettenCorrect answer
    Legend
    March 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 page or reloads it.

    2Charlie
    2CharlieAuthor
    Inspiring
    March 17, 2016

    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.

    Carl Von Stetten
    Legend
    March 17, 2016

    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?