469,330 Members | 1,373 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

How can I create a confirmation box in ColdFusion?

Haitashi
I had the following code that would create a javascript confirmation page. This code lived inside a form which wouldn't submit until the user clicked the Ok button.

Expand|Select|Wrap|Line Numbers
  1. <input type="image" onclick="return confirm('You will not be able to change your answers if you submit now.\nAre you sure you want to submit this test?');" name="SubmitTestButton" src="images/submit_test.jpg" value="Submit Test" class="submit_test_button" />
I've bee trying to achieve the same effect using CFWINDOW. Only, once the window comes up the form automatically submits.

Current code:
Expand|Select|Wrap|Line Numbers
  1.         <form name="TestForm" [...]>
  2.  [OTHER CODE]
  3.  
  4.                 <p><input type="image" onclick="ColdFusion.Window.show('submitTest')" name="SubmitTestButton" src="images/submit_test.jpg" value="Submit Test" class="submit_test_button" /></p>
  5.             </cfif>
  6.         </form>
  7.  
  8.         <cfwindow name="submitTest"
  9.             center="true"
  10.             closable="true"
  11.             draggable="false"
  12.             height="200"
  13.             width="200"
  14.             initShow="false"
  15.             modal="true"
  16.             refreshOnShow="false"
  17.             resizable="false">
  18.                     <cfoutput>
  19.                         <p>You will not be able to change your answers if you submit now. </p><p>Are you sure you want to submit this test?</p>
  20.                         <input type="image" name="SubmitTestButton" src="images/submit_test.jpg" value="Yes, Please Sumbit" class="submit_test_button" /></p>
  21.  
  22.                     </cfoutput>
  23.         </cfwindow>
I've been trying to figure out a way to create a coldfusion confirmation box, essentially. Any help or direction will be appreciated. I will post back the final code for reference.
May 2 '08 #1

✓ answered by Haitashi

I am using cfwindow. =) This is the cfwindow code that I have in place of what is written at line 23 above.

Expand|Select|Wrap|Line Numbers
  1.          <cfajaximport cssSrc="styles/cfskins/" />        
  2.         <cfwindow name="cfwinconfirm"
  3.             center="true"
  4.             closable="true"
  5.             draggable="false"
  6.             height="200"
  7.             width="380"
  8.             initShow="false"
  9.             modal="true"
  10.             resizable="false">
  11.                 <cfoutput>
  12.                     <span class="test_confirmation_window">
  13.                     <p>    You will not be able to change your answers if you submit now. </p><p>Are you sure you want to submit this test?</p>
  14.                     <p>    <input type="image" onclick="hideAndSubmit('cfwinconfirm','TestForm'); return false;" name="confirmSubmit"  src="images/submit_button.gif" class="confirmation_test_button" />
  15.                         <input type="image" onclick="hideCfWindowConfirm(); return false;" name="cancel" src="images/cancel_button.gif" class="confirmation_test_button" />
  16.                     </p>
  17.                     </span>
  18.                 </cfoutput>
  19.         </cfwindow>

7 9238
acoder
16,027 Expert Mod 8TB
If it's just an image button, why does it submit?

You need to return true or false to control the form submission, but cfwindow doesn't return anything, but what you can do is use the Coldfusion.Window.onHide function to define a function to run when the window is "closed".
May 3 '08 #2
What you're saying makes sense but what if after clicking submit, they get that box and they decide they don't want to submit after all - if they close the window then it would still submit, wouldn't it?
May 5 '08 #3
acoder
16,027 Expert Mod 8TB
Not quite. If, for example, you return false when calling from onsubmit, the form will not submit.
May 5 '08 #4
Ok. I did something based off what you said. I did implement some javascript, though.

Expand|Select|Wrap|Line Numbers
  1. <form name="ParentForm" id="ParentForm" action="action.cfm" method="post">
  2.  
  3.     <input type="hidden" name="TestFormField" value="booyah" />
  4.     <input type="submit" value="Submit the Parent Form" onclick="showCfWindowConfirm(); return false;" />
  5.  
  6. </form>
  7.  
  8. <script type="text/javascript">
  9.     function showCfWindowConfirm() {
  10.         ColdFusion.Window.show('cfwinconfirm');
  11.     }
  12.  
  13.     function hideCfWindowConfirm() {
  14.         ColdFusion.Window.hide('cfwinconfirm')
  15.     }
  16.  
  17.     function hideAndSubmit(cfwindowname,formID) {
  18.         ColdFusion.Window.hide(cfwindowname)
  19.         document.getElementById(formID).submit();
  20.     }
  21. </script>
  22.  
  23. <cfwindow initShow="false" title="Confirm" name="cfwinconfirm" modal="true" center="true" source="confirm.cfm" width="300" height="150"/>
and in confirm.cfm:

Expand|Select|Wrap|Line Numbers
  1. <a href="" onclick="hideAndSubmit('cfwinconfirm','ParentForm'); return false;">Confirm</a>
  2. <a href="" onclick="hideCfWindowConfirm(); return false;">Cancel</a>
Note: this is the the skeleton of what I did just for demonstration purposes. It does not reflect how the scripts and files were placed in my actual application.

As always, I really appreciate the help!
May 5 '08 #5
acoder
16,027 Expert Mod 8TB
That seems about right.

If you wanted to really get fancy, you could try replacing the confirm dialog with a cfwindow dialog, though you may need to extend it to return values.
May 6 '08 #6
I am using cfwindow. =) This is the cfwindow code that I have in place of what is written at line 23 above.

Expand|Select|Wrap|Line Numbers
  1.          <cfajaximport cssSrc="styles/cfskins/" />        
  2.         <cfwindow name="cfwinconfirm"
  3.             center="true"
  4.             closable="true"
  5.             draggable="false"
  6.             height="200"
  7.             width="380"
  8.             initShow="false"
  9.             modal="true"
  10.             resizable="false">
  11.                 <cfoutput>
  12.                     <span class="test_confirmation_window">
  13.                     <p>    You will not be able to change your answers if you submit now. </p><p>Are you sure you want to submit this test?</p>
  14.                     <p>    <input type="image" onclick="hideAndSubmit('cfwinconfirm','TestForm'); return false;" name="confirmSubmit"  src="images/submit_button.gif" class="confirmation_test_button" />
  15.                         <input type="image" onclick="hideCfWindowConfirm(); return false;" name="cancel" src="images/cancel_button.gif" class="confirmation_test_button" />
  16.                     </p>
  17.                     </span>
  18.                 </cfoutput>
  19.         </cfwindow>
May 6 '08 #7
acoder
16,027 Expert Mod 8TB
Nice. Thanks for posting and glad to see that you've got a working solution.
May 6 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

60 posts views Thread by English Teacher | last post: by
16 posts views Thread by worzel | last post: by
4 posts views Thread by William Fields | last post: by
acoder
reply views Thread by acoder | last post: by
acoder
7 posts views Thread by acoder | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.