Skip to main content
Participant
March 20, 2007
Question

Processing nulls from a form

  • March 20, 2007
  • 1 reply
  • 204 views
Hi, I have a query which populates a form, which the user can then amend. I am updating the database with the form data. The problem i have is that if a user amends a field to null (which they are allowed to do) my processing goes wrong as i am treating the form fields as lists.
I think i need to put the form data into an array? but i'm not sure how to structure it. My current processing code is:
<cfset ElementNumber = 0>

<cfloop list="#ModuleCode#" index="ListElement">
<cfset ElementNumber = ElementNumber + 1>
<cfif UpdatesAllowed EQ "Y">
<cfquery name="qUpdate" datasource="DMDs">
UPDATE utbl_main
SET Flag2005 = '#ListGetAt(Flag2005,ElementNumber)#',
statusnextyr = '#ListGetAt(statusnextyr,ElementNumber)#',
ActSem1 = '#ListGetAt(ActSem1,ElementNumber)#',
ActSem2 = '#ListGetAt(ActSem2,ElementNumber)#',
ActSem3 = '#ListGetAt(ActSem3,ElementNumber)#',
ActSemCom = '#ListGetAt(ActSemCom,ElementNumber)#'
WHERE ModuleCode = '#ListElement#'
</cfquery>
<cfelse>
<cfquery name="qUpdate" datasource="DMDs">
UPDATE utbl_main
SET Flag2005 = '#ListGetAt(Flag2005,ElementNumber)#',
ActSemCom = '#ListGetAt(ActSemCom,ElementNumber)#'
WHERE ModuleCode = '#ListElement#'
</cfquery>
</cfif>
</cfloop>

ANy help much appreciated. Cheers
    This topic has been closed for replies.

    1 reply

    Inspiring
    March 20, 2007
    When you say that the user sets the ElementNumber field to null, do you mean an empty field ("") or the actual text null. I'm assuming the former if you are having problems with your form processing. You could try replacing the empty form item with some sort of placeholder text ("" or Null) before you starting looping through your lists, which would allow you to maintain your list postions:

    <cfset ActSem1 = replace(actSem1, ",,", ",null,", "all")>