Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I create a confirmation box in ColdFusion?

Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#1: May 2 '08
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.

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: May 3 '08

re: How can I create a confirmation box in ColdFusion?


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".
Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#3: May 5 '08

re: How can I create a confirmation box in ColdFusion?


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?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: May 5 '08

re: How can I create a confirmation box in ColdFusion?


Not quite. If, for example, you return false when calling from onsubmit, the form will not submit.
Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#5: May 5 '08

re: How can I create a confirmation box in ColdFusion?


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!
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: May 6 '08

re: How can I create a confirmation box in ColdFusion?


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.
Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#7: May 6 '08

re: How can I create a confirmation box in ColdFusion?


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>
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#8: May 6 '08

re: How can I create a confirmation box in ColdFusion?


Nice. Thanks for posting and glad to see that you've got a working solution.
Reply