-4

Like the title says, I am invoking a CFC from a FORM. This is how I am doing it now, but there has to be a better way.

Form:

<cfform action="choice.cfm" method="post">
    <cfinput type="hidden" name="method" value="DeleteMessage">
    <cfinput type="hidden" name="announcement" value="#announcement#">
    <cfinput type="hidden" name="ID" value="#ID#">
    <cfinput type="submit" value="Delete" name="form.OKbutton1" onclick="return confirm('Are you sure you want to delete?');">
</cfform>

Action page:

<cfif IsDefined("form.OKbutton1")> 
    <cfinvoke component="pdprojects.scr.changedisablesysequipment" 
         method="DeleteMessage" 
         returnvariable="DeleteMessages" 
         argumentCollection="#Form#" />
</cfif>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
user1253239
  • 199
  • 2
  • 3
  • 13

1 Answers1

0

I figured out a way to streamline this with jquery and cfc. Page updates fast, and no worries if the person hits back button or refreshes the page. You could probably do a lot more with JQuery to append a div tag instead of location.reload(); (Page Refresh) at the end of the call.

CF Call

<cfajaxproxy cfc="pdprojects.scr.changedisablesysequipment" jsclassname="choice_cls">

Here is the jquery

<script src="/js/jquery-1.7.1.min.js">


<script>
$(document).ready(function(){
    $("#OKbutton").click(function(){
        if ($('#Announcement').val() == "") {
            alert("Please enter message in the text area!");
        }
        else {
            var instance = new choice_cls();
            instance.setForm("enterit");
            instance.InsertMessage();
            location.reload();
        }
    });
     $("#OKbutton1").click(function(){
            var instance = new choice_cls();
            instance.setForm("deleteit");
            instance.DeleteMessage();
            location.reload();
    });
});

Here is my html

<cfform action="" id="enterit" name="enterit" method="post"> 
<cfinput type="hidden" value="#session.username#" name="thisname">  
<cftextarea cols="50" rows="8" name="Announcement"></cftextarea><br>
<cfinput type="button" value="Enter Announcement" name="OKbutton" id="OKbutton">
</cfform>

<cfform action="" id="deleteit" name="deleteit"  method="post">
<cfinput type="hidden" name="method" value="DeleteMessage">
    <cfinput type="hidden" name="announcement" value="#announcement#">
    <cfinput type="hidden" name="ID" value="#ID#">
    <cfinput type="button" value="Delete" name="OKbutton1" onclick="return confirm('Are you sure you want to delete?');">
 </cfform>

Then just create your CFC for coldfusion!

user1253239
  • 199
  • 2
  • 3
  • 13