Skip to main content
Inspiring
June 25, 2010
Answered

Form processing undefined values

  • June 25, 2010
  • 2 replies
  • 1083 views

I have a form with 50 fields.

Sometimes when my users submit the form, if the field value is zero, they delete the input box completely.

So when the form is submitted and they get to the processing page ; the form field value for the field they deleted is  "".

This is causing problems as the form value is "", where it should be 0.00

I have CFPARAM's at the processing page. But I guess since the value is defined ("") they are not being used.

Is there a way to code the form processing page so that if any of the form fields are "" that they default to a 0.00 value?

Pat

    This topic has been closed for replies.
    Correct answer ilssac

    You could do it in a loop and|or a function.

    I.E.

    <cfloop collection="#form#" item="field">

         <cfif len(trim(form[field])) EQ 0>

              <cfset form[field] = 0.00>

         </cfif>

    </cfloop>

    You may need to modify this it there are some fields you do not want to test this way.

    2 replies

    ilssac
    Inspiring
    June 25, 2010

    Additionaly, you may want to explore a JavaScript solution that does similar on the client side.  Test the value of the field onChange, and if the field is empty or someother non-valid value, change it to 0.00.

    Of course, this does not replace the above server side code.  Always revalidate on the server.  But this might train users to correctly utilzie your form.

    ilssac
    Inspiring
    June 25, 2010

    Something more complex then:

    <cfif len(trim(form.badField)) EQ 0>
      <cfset form.badField = 0.00>
    </cfif>
    weezerboyAuthor
    Inspiring
    June 25, 2010

    Ian,

    I was hoping to avoid doing this for all 50 values.

    But it may be what I need to do.

    Pat

    ilssac
    ilssacCorrect answer
    Inspiring
    June 25, 2010

    You could do it in a loop and|or a function.

    I.E.

    <cfloop collection="#form#" item="field">

         <cfif len(trim(form[field])) EQ 0>

              <cfset form[field] = 0.00>

         </cfif>

    </cfloop>

    You may need to modify this it there are some fields you do not want to test this way.