Skip to main content
Inspiring
October 4, 2012
Question

Run Update Query when the OK button is clicked, not when the page loads..

  • October 4, 2012
  • 2 replies
  • 1214 views

I have an Insert Form like so:

with <form method="post" id="form2" action="<cfoutput>#Request.KT_escapeAttribute(Request.KT_getFullUri())#</cfoutput>">

        <input type="submit" data-mini="true" name="Insert1" id="Insert1" value="OK" />

I also need to run the following Update Query if the User clicks on OK..

---------------------------------------------------------------------

<!--- Update the Status to Rejected in the tbltickets table --->

      <cfquery datasource="care">  

    UPDATE tbltickets

SET ttstatus=<cfqueryparam value="Rejected" cfsqltype="cf_sql_varchar">

WHERE ttNum=<cfqueryparam cfsqltype="cf_sql_varchar" value="#url.id#">

  </cfquery>

- If I add this second query in the head of the page, it runs fine..

- But I need it to only run when the OK button is clicked, not when the page loads..

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    December 3, 2012

    Not quite sure what you're doing, but can you check to see if the submit button (Insert1) has a value of "OK"? (Which only happens if you have pressed the OK button?)

    jligAuthor
    Inspiring
    November 29, 2012

    The solution was to wrap my UPDATE querie(s) in the following cfif:

    <!--- Hold off doing the Update unless the the form has been submitted --->

    <cfif isdefined("form.KT_Insert1")>

    <!--- Update the Status to Rejected in the tbltickets table --->

          <cfquery datasource="care"> 

        UPDATE tbltickets

    SET ttstatus=<cfqueryparam value="Rejected" cfsqltype="cf_sql_varchar">

    WHERE ttNum=<cfqueryparam cfsqltype="cf_sql_varchar" value="#url.id#">

      </cfquery>

    </cfif>