Skip to main content
Inspiring
October 24, 2025
Answered

clear down input fields once user presses submit

  • October 24, 2025
  • 1 reply
  • 98 views

First off – thanks for all the fantastic help so far.  Just one last issue to resolve.

 

Can I clear down the input fields once the user presses Submit to update the database?

Otherwise if they press the submit button again, it add more (duplicate) records to the database.

 

(my other option if to manage it in SQL code, ignoring duplicate entries)

 

How it works

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

Page displays a variable list of rows, and a field to allow entry of a new date value on each row (as each row may have a different value, or indeed no changes).  Each time a value is entered, we want to create a new “change log” record for that change.

example layout :

                key     current value    data entry field to allow new value

                key     current value    data entry field to allow new value - optional 2nd row

                key     current value    data entry field to allow new value - optional 3rd row, etc

 

Code (from BKBK)

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

<cfset table1 = queryNew("key,logDate,data","Integer,Date,Varchar",

[

{key=123,logDate="19/10/2025",data="Data in 1st row"},

{key=456,logDate="22/10/2025",data="Data in 2nd row"},

{key=789,logDate="21/10/2025",data="Data in 3rd row"}

])>

<cfdump var="#form#" label="Dump of form scope">

<cfoutput>

<cfform action="#CGI.SCRIPT_NAME#"  method="POST" name="FormX"> 

<table>

<cfloop query="table1">

<tr>

                <td>key: </td><td>#key#</td>

               

                <cfif isDefined("FORM.NEWVALUE#Key#") and FORM['NEWVALUE#key#'] is not ''>  

                                <td>New value: </td><td><cfinput type="date" name="NEWVALUE#key#" value="#FORM['NEWVALUE#key#']#"></td>

                                <b style="color:purple">

                                <!---<cfquery> commented out for testing  --->     

                                         INSERT INTO table2 (id,dateValue)

                                       VALUES (#key#, '#FORM['NEWVALUE#key#']#);       

                              <!---</cfquery>--->

                               

?? can we clear out FORM.NEWVALUE#Key#" here ?

 

                                </b>    

                <cfelse>

                                <td>New value: </td><td><cfinput type="date" name="NEWVALUE#key#"></td>

                </cfif>

</tr>

</cfloop>

<table>

 

<cfinput type="submit" name="submit" value="Submit">                       

</cfform>

</cfoutput>

Correct answer BKBK

Of course. You could use

<cfinput type="date" name="NEWVALUE#key#">

in place of 

<cfinput type="date" name="NEWVALUE#key#" value="#FORM['NEWVALUE#key#']#">

 

1 reply

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
October 24, 2025

Of course. You could use

<cfinput type="date" name="NEWVALUE#key#">

in place of 

<cfinput type="date" name="NEWVALUE#key#" value="#FORM['NEWVALUE#key#']#">

 

Inspiring
October 27, 2025

Brilliant!   I love those one line fixes that just make it all work.

Thanks 

Paul

BKBK
Community Expert
Community Expert
October 27, 2025

Thanks for your kind words, @paul_durrant .