Search code examples
coldfusioncoldfusion-9coldfusion-10

element undefined error


I am trying to add a search feature to my cfgrid. But I am getting an "Element NAME is undefined in FORM. error". The first time the page loads, it displays the grid. But after I press the search button, the error occurs. Here is the code:

 <form name="DropDown" method="post">
    <!--- query DB for the first drop down list --->
    <cfquery name="Getprocedures" datasource="caselogs">
        SELECT distinct procedures.procedure_name, procedures.procedure_id 
        FROM case_logs inner join procedures 
                     on procedures.procedure_id=case_logs.procedure_id
        WHERE case_logs.trainee_id=#form.name#
    </cfquery>


    <cfform action="#cgi.script_name#" method="post"> 
        <select name="Ddl_form" size="1">
        <cfoutput query="Getprocedures">
            <option value="#procedure_id#" <cfif isDefined('form.Ddl_form')> <cfif form.Ddl_form eq "#procedure_id#">selected</cfif> </cfif>> #procedure_name#</option>
        </cfoutput>
        </select>

        Status 
        <select name="Ddl_status" size="1">
            <option value="P"<cfif isDefined('form.Ddl_status')> <cfif form.Ddl_status eq "P">selected</cfif> </cfif>>In Progress</option>
            <option value="S"<cfif isDefined('form.Ddl_status')> <cfif form.Ddl_status eq "S">selected</cfif> </cfif>>Submitted</option>
            <option value="R"<cfif isDefined('form.Ddl_status')> <cfif form.Ddl_status eq "R">selected</cfif> </cfif>>Reviewed</option>
            <option value="-1" <cfif isDefined('form.Ddl_status')> <cfif form.Ddl_status eq "-1">selected   </cfif> </cfif>>All</option>
        </select>
        <input type="submit" name="search" value="Search">
    </cfform>

    <cfif isdefined('form.search')>
          <cfquery name="qGetBooks" datasource="caselogs">
                 SELECT CASE_LOGS.performed_dt,CASE_LOGS.submitted_dt,procedures.procedure_name,hospitals.hospital_code,case_logs.status 
                 FROM  case_logs
                        inner join procedures on procedures.procedure_id = case_logs.procedure_id
                        inner join hospitals on hospitals.hospital_id = case_logs.hospital_id
                 WHERE case_logs.trainee_id=2 and case_logs.status='#Form.Ddl_status#' and case_logs.procedure_id=#FORM.Ddl_form#
       </cfquery>
   <cfelse>
          <cfquery name="qGetBooks" datasource="caselogs">
                 SELECT CASE_LOGS.performed_dt,CASE_LOGS.submitted_dt,procedures.procedure_name,hospitals.hospital_code,case_logs.status 
                 FROM   case_logs
                        inner join procedures on procedures.procedure_id = case_logs.procedure_id
                        inner join hospitals on hospitals.hospital_id = case_logs.hospital_id
                 WHERE  case_logs.trainee_id=2 and case_logs.status='P' 
          </cfquery>
   </cfif>  

   <cfform name="gridform"> 
          <cfgrid name="BooksGrid" 
                 format="HTML" 
                 selectmode="row"
                 query="qGetBooks" 
                 title="Students"
                 insert="true"
                 insertbutton="Insert Book"
                 width="500">
              <cfgridcolumn name="performed_dt" header="DatePerformed" />
              <cfgridcolumn name="submitted_dt" header="SubmitedDate" />
              <cfgridcolumn name="procedure_name" header="Procedure" />
              <cfgridcolumn name="hospital_code" header="Hospital" />
              <cfgridcolumn name="status" header="Status" />
          </cfgrid> 
   </cfform>

Here is the error:

The error occurred in C:/ColdFusion10/cfusion/wwwroot/Caselogs/Trainee/caselogs.cfm: line     10

   8 :     select distinct procedures.procedure_name, procedures.procedure_id from case_logs 
  9 :     inner join procedures on procedures.procedure_id=case_logs.procedure_id
 10 :      where case_logs.trainee_id=#form.name#
 11 :   </cfquery>
 12 : 

Solution

  • In your search, you're not passing the name element along, just add it as a hidden element to the search form:

    <input type="hidden" name="name" value="#form.name#">