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?
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
...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.
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.
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?
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.
Copy link to clipboard
Copied
That makes sense. Did that come up in a previous thread on the forum? Sounds vaguely familiar.
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.