jjasper0729
jjasper0729

Reputation: 295

ColdFusion 10 getting element is undefined in form error

I've got a ColdFusion 10 form, to which I'm adding a new multiple select list

<SELECT multiple="multiple" id="icd9list" 
    name="icd9list" 
    size="2" 
    class="pageText2" 
    style="width:400px;">
</SELECT>

It shows up on the form correctly and I can get items added to it with JavaScript, but when I go to process the form, the form action page is giving the following error:

Element ICD9LIST is undefined in FORM.

I've added cfparam tags on the initial form page, as well as the form action page where I'm getting the error.

Can't for the life of me figure out why it's not passing the form element to the action page. The method is post, so it should be picking it up. All of the other form elements on the page are picked up fine.

<cfform action="updform.cfm" name="custform" method="POST">

I also tried to use custform.icd9list and got the same issue:

Element ICD9LIST is undefined in CUSTFORM.

This page is some VERY legacy code that we can't really go back and refactor too much. The only thing I'm thinking is that when the page first loads, the multiple select option is blank and then we are adding options to it via javascript from a pop-out window after the fact. When I inspect the element in Chrome, after I've added options to it, they are there, but I'm wondering if it's still being treated as a blank multiple select list. I do know that if I remove the multiple attribute and treat the form element as a single drop down list that it shows up in the form dump with a value, but only the first (or whatever selected) value.

Beginning to think the answer may be to have a hidden field with the option values populated and let the form read that.

Upvotes: 3

Views: 1566

Answers (3)

needingSomeAnswers
needingSomeAnswers

Reputation: 13

How are you calling on the form? Are you using form.variable or icd9list.variable? You shouldn't have to give it an ID or name unless there are multiple forms on the page. You can just name and ID your element and reference it like this: form.name

Upvotes: 0

James A Mohler
James A Mohler

Reputation: 11120

It sounds like you need one of two things

Either required it on the client side

<SELECT multiple="multiple" required id="icd9list" name="icd9list" size="2" class="pageText2" style="width:400px;">
...
</SELECT>

Or make sure ColdFusion can handle it not existing on the server side.

<cfparam name="icd9list" default="">

As pointed out,

<cfparam name="form.icd9list" default="">

will get an even tighter scope

Upvotes: 2

SOS
SOS

Reputation: 6550

Adding options to a multiple select list isn't enough. They have to be selected as well. Otherwise, the list isn't considered a successful control and the field won't be passed to the action page (emphasis mine)

A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.

However:

  • Controls that are disabled cannot be successful.
  • If a form contains more than one submit button, only the activated submit button is successful.
  • All "on" checkboxes may be successful.
  • For radio buttons that share the same value of the name attribute, only the "on" radio button may be successful.
  • For menus, the control name is provided by a SELECT element and values are provided by OPTION elements. Only selected options may be successful. When no options are selected, the control is not successful and neither the name nor any values are submitted to the server when the form is submitted.
  • The current value of a file select is a list of one or more file names. Upon submission of the form, the contents of each file are submitted with the rest of the form data. The file contents are packaged according to the form's content type.
  • The current value of an object control is determined by the object's implementation.

I suspect the form isn't forcing the items to be "selected" before the form is submitted and that's why nothing shows up on the action page.

Upvotes: 4

Related Questions