Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

clear down input fields once user presses submit

Participant ,
Oct 24, 2025 Oct 24, 2025

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>

TOPICS
Getting started
82
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 24, 2025 Oct 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#']#">

 

Translate
Community Expert ,
Oct 24, 2025 Oct 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#']#">

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 27, 2025 Oct 27, 2025

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

Thanks 

Paul

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2025 Oct 27, 2025
LATEST

Thanks for your kind words, @paul_durrant .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources