6 Replies Latest reply on Jun 18, 2007 3:41 PM by silviasalsa

    insert values in field database by check boxes

    silviasalsa



      I had a similar error and probem when using dropdown instead of a check box. It was resolved by putting SELECT name="CarMake in the drop down.

      But in the checkbox, I don’t know?
      I seems like the problem is the action page has the Form.carmake but the entry page does not. What am I missing and where do I put in the entry page below.


      The key goal is to have checkboxes checked to insert values into the database field carmake based on what is checked.


      If the checkbox Honda is checked then
      it inserts to the carmake field the value Honda.

      If the checkbox Toyota is checked then
      it inserts to the carmake field the value Toyota.

      If both are checked then 2 records are inserted both values
      Honda and Toyota.

      Same for the last option.

      Thanks for all your help


      Here is the error again

      error:
      Error Occurred While Processing Request
      Element CARMAKE is undefined in FORM.

      12:21:50.050 - Expression Exception - in C:\CFusionMX7\wwwroot\Author\CarAddAction.cfm : line 16
      Element CARMAKE is undefined in FORM.

      line 16 is:
      '#Trim(Form.carmake)#',
      Attach Code


      <!------------here is the form------------>
      <html>
      <head>
      </head>

      <body>


      <h1> </h1>

      <table>
      <cfform action="CarAddAction.cfm" method="POST">
      <tr>
      <td>Honda:</td>
      <td><center><input type="checkbox" name="HONDA_MODEL" value="HONDA" checked></center></td>
      </tr>
      <tr>
      <td>Toyota:</td>
      <td><center><input type="checkbox" name="Toyota_MODEL" value="Toyota" Unchecked></center></td>
      </tr>
      <tr>
      <td>SUBARU:</td>
      <td><center><input type="checkbox" name="SUBARU_MODEL" value="SUBARU" unchecked></center></td>
      </tr>



      <tr><td>Honda Model</td>
      <td>
      <input type="Text"
      name="Honda_Model"
      Value=""
      size="22"
      maxlength="20">
      </td>
      <tr></tr>
      <tr><td>Toyota Model</td>
      <td>
      <input type="Text"
      name="Toyota_Model"
      Value=""
      size="22">
      </td>
      <tr></tr>
      <tr><td>Subaru Model</td>
      <td>
      <input type="Text"
      name="Subaru_Model"
      Value=""
      size="22">
      </td>
      <tr></tr>
      <td> </td>
      <td>
      <input type="submit" value="Add make to Database">
      </td>
      </tr>

      </cfform>
      </table>

      </body>
      </html>



      <!--------Action page
      --------->
      <cfdump var = "#form#">
      <cfquery name="InsertCarInfo"
      datasource="#Request.MainDSN#">
      INSERT INTO Car_tab(
      car_Make,
      Honda_Model,
      Toyota_Model,
      Subaru_Model

      )
      VALUES (

      '#Trim(Form.carmake)#',
      '#Trim(Form.Honda_Model)#',
      '#Trim(Form.Toyota_Model)#',
      '#Trim(Form.Subaru_Model)#'
      )
      </cfquery>

        • 1. Re: insert values in field database by check boxes
          MichaelSJudd
          You don't have a field named "carmake" in the form you posted here.

          Also, your checkbox and text field have the same names duplicated in each, which can be a problem, or at the least very confusing.

          Your checkboxes would all need the same name of "carmake" i.e. - "name="carmake". HOWEVER - you could end up with multiple values in the car_Make field in your db, unless that is what you want. In that case yes, simply name each checkbox "carmake", but each with a different value. (Be sure to know how to insert a record using "ListQualify" - you can find this in CF help menus, etc. or in SQL manuals).

          Let me know how that works out.
          • 2. Re: insert values in field database by check boxes
            insuractive Level 3
            Let's take a step back and expand a little on what MichaelSJudd mentioned -

            1) On your action page, name all your checkboxes the same - "carmake" and set the value="" attribute to the different Makes (Toyota, Honda, etc). When a user submits this form, the data will be sent to the action page as a comma-delimited list of each item that was checked.

            i.e.
            if Honda was checked: carmake = Honda
            if both Honda and Toyota were checked: carmake = Honda,Toyota

            IMPORTANT NOTE: if you are not used to working with checkboxes in HTML forms, you should be aware that if none of the checkboxes are checked, the form is not sent to the action page. Basically, if nothing is checked then the variable form.carmake won't exist on the processing page. Make sure you use <cfparam> to default this value so you don't wind up with "Undefined in FORM" errors

            2) On your processing page, it looks like your car_make field might be able to accomodate a comma delimited list of makes, in which case your query would look something like this (I recommend using <cfqueryparam>):

            INSERT INTO Car_tab(
            car_Make,
            Honda_Model,
            Toyota_Model,
            Subaru_Model)
            VALUES (
            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.carmake)#">,
            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Honda_Model)#">,
            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Toyota_Model)#">,
            <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Subaru_Model)#">
            )
            • 3. Re: insert values in field database by check boxes
              silviasalsa Level 1



              thanks.


              I have changed the nameed of the check boxes for all 3 to
              to name="CARMAKE"

              is this what you are talking about.
              thanks?

              I actually wanted to hold back on the 2. and 3. cfparam. i hope to get to it after this first task. thanks



              still the same error.
              Element CARMAKE is undefined in FORM.
              line 16
              Element CARMAKE is undefined in FORM.


              line 16 in the action page is '#Trim(Form.CARMAKE)#',




              please see my code.

              thanks Help


              • 4. Re: insert values in field database by check boxes
                insuractive Level 3
                Are you checking one or more of the checkboxes before proceeding? Remember what I said about the checkbox form field not existing on the processing page unless 1 or more checkboxes are checked on your form. Make sure to use <cfparam name="Form.carmake" default=""> to avoid this issue.

                What happens when you take a look at the output of your form dump? Are your fields present?
                • 5. Re: insert values in field database by check boxes
                  silviasalsa Level 1
                  thanks

                  i have checked one
                  and
                  one or more.

                  still is goving me the same error.


                  i have also changed
                  the action page's insert into
                  to:



                  INSERT INTO Car_tab(
                  car_Make,
                  Honda_Model,
                  Toyota_Model,
                  Subaru_Model)
                  VALUES (
                  <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.carmake)#">,
                  <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Honda_Model)#">,
                  <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Toyota_Model)#">,
                  <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#Trim(Form.Subaru_Model)#">
                  • 6. Re: insert values in field database by check boxes
                    silviasalsa Level 1
                    never mind the error.

                    it actually works Many thanks.