Skip navigation
Currently Being Moderated

Adding a CFCASE to a Coldfusion SELECT dropdown

Nov 15, 2012 3:06 PM

I have the following simple dropdown on my form:

---------------------------------------------------------

                          <select name="ttTo" id="ttTo" >

                            <option value="">Choose One</option>

                            <cfoutput query="rsTicketTo">

                              <option value="#rsTicketTo.ttEmail#">#rsTicketTo.ttDesc#</option>

                            </cfoutput>

                          </select>

                        </div>

--------------------------------------------------------

 

How would I change my select above to include the sample functionality below but using ColdFusion?

Note: The #TicketType# variable below will be on the page but not from the same table as the ttTo value.

 

       // Check where to send support request to...

       switch (trim($fTicketTo))

       {

       case "":

$error = 1;

$tMessage = "You must select a valid Recipient!";

break;

 

       case "Service":

if ($fTicketType == "T1")

{

$fTicketTo = 'serv1@xyz.com';

}

else

{

$fTicketTo = 'serv2@xyz.com';

}

break;

 

       case "Outage":

$fTicketTo = 'serv1@xyz.com';

break;

 

       case "Data":

$fTicketTo = 'data@xyz.com';

break;

 

       case "Voice":

$fTicketTo = 'voice@xyz.com';

break;

 

       case "T1":

$fTicketTo = 't1@xyz.com';

break;

 

       case "Wire":

$fTicketTo = 'wire@xyz.com';

break;

 

       case "Phone":

$fTicketTo = 'pst@xyz.com';

break;

 

       case "Prov":

$fTicketTo = 'prov@xyz.com';

break;

       case "Cust":

$fTicketTo = 'cc@xyz.com';

break;

 

       }

 
Replies
  • Currently Being Moderated
    Nov 15, 2012 7:03 PM   in reply to jlig

    Using switch/case inside a select control doesn't make any sense.  What are you hoping to accomplish?

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2012 12:32 AM   in reply to jlig

    It isn't clear which query column corresponds to the case values 'service', 'outage', 'data', etc. There are also inconsistenties. You have defined the cases as subsequent values of trim($fTicketTo). Yet, within each case block, you again define a new variable of the same name ($fTicketTo). Another inconsistency is that "T1" is at once a value for $fTicketType and for trim($fTicketTo).

     

    If all you wished to do is to convert the given switch-case into a select-box, then you could proceed as follows:

     

    <cfform>

    <cfselect name="ttTo" id="ttTo" required="yes" message="You must select a valid Recipient!">

    <option value="">Choose support request</option>

    <option value="serv1@xyz.com">T1 Service</option>

    <option value="serv2@xyz.com">Service(except T1)</option>

    <option value="serv1@xyz.com">Outage</option>

    <option value="data@xyz.com">Data</option>

    <option value="voice@xyz.com">Voice</option>

    <option value="t1@xyz.com">T1</option>

    <option value="wire@xyz.com">Wire</option>

    <option value="pst@xyz.com">Phone</option>

    <option value="prov@xyz.com">Prov</option>

    <option value="cc@xyz.com">Cust</option>

    </cfselect>

    <cfinput name="sbmt" type="submit" value="Submit">

    </cfform>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2012 2:33 AM   in reply to jlig

    In that case, my first choice would be to use the case construct in the actual query to get the appropriate email address.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 16, 2012 8:35 AM   in reply to jlig

    There are a few of ways to do it. 

     

    One is to set up cascading selects bound to cfc's.  If you choose this option, you use your cfc to pass the correct email to the second select.

     

    Another is to figure out the correct email with coldfusion code once the form has been submitted.  This would be my preference.

     

    Another is to use javascript to look at the values of the two selects and put the email address into a hidden field.

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 7:13 AM   in reply to jlig

    <cfform>

    <cfselect name="ttTo" id="ttTo" required="yes" message="You must select a valid Recipient!">

    <option value="">Choose support request</option>

    <cfif $fTicketType EQ "T1">

        <option value="serv1@xyz.com">Service</option>

    <cfelse>

        <option value="serv2@xyz.com">Service</option>

    </cfif>

    <option value="serv1@xyz.com">Outage</option>

    <option value="data@xyz.com">Data</option>

    <option value="voice@xyz.com">Voice</option>

    <option value="t1@xyz.com">T1</option>

    <option value="wire@xyz.com">Wire</option>

    <option value="pst@xyz.com">Phone</option>

    <option value="prov@xyz.com">Prov</option>

    <option value="cc@xyz.com">Cust</option>

    </cfselect>

    <cfinput name="sbmt" type="submit" value="Submit">

    </cfform>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 1:36 PM   in reply to jlig

    In my opinion, all the preconditions you're setting make the issue unnecessarily complex. The values are coming in via a form, so you cannot avoid the effects of user-input. That said, the following is consistent with what you already have

     

    <cfquery datasource="care" result="insertQueryResult">  

        INSERT INTO tbltickets (ttDate,  ttType, ttTo)

        VALUES (<cfqueryparam cfsqltype='CF_SQL_timestamp' value='#CreateODBCDateTime(now())#'>

        ,<cfif IsDefined("FORM.ttDateDue") AND FORM.ttDateDue NEQ "">

            <cfqueryparam value="#FORM.ttDateDue#" cfsqltype="cf_sql_timestamp">

        <cfelse>

            NULL

        </cfif>

        ,<cfif IsDefined("FORM.ttType") AND FORM.ttType EQ "">

            <cfqueryparam value="#FORM.ttType#" cfsqltype="cf_sql_varchar" maxlength="30">

        <cfelse>

            ''

        </cfif>

        ,<cfif IsDefined("FORM.ttType")>

            <cfif FORM.ttType EQ "">

                ''

            <cfelseif FORM.ttType EQ "T1">

                <cfqueryparam value="serv1@xyc.com" cfsqltype="cf_sql_varchar">

            <cfelse>

                <cfqueryparam value="serv2@xyc.com" cfsqltype="cf_sql_varchar">

            </cfif>

        </cfif>

        )

    </cfquery>

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 2:46 PM   in reply to jlig

    If you want to update a value in a select based on the value of another form field, you have to use javascript.  I wouldn't bother.  I'd simply generate the email address I wanted when I process the submitted form.    

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 11:49 PM   in reply to BKBK

    On second thoughts, the following is more in tune as last term:

     

    <cfif IsDefined("FORM.ttType")>

            <cfif FORM.ttType EQ "T1">         

                    <cfqueryparam value="serv1@xyc.com" cfsqltype="cf_sql_varchar">

            <cfelseif FORM.ttType NEQ "">               

                   <cfqueryparam value="serv2@xyc.com" cfsqltype="cf_sql_varchar">

            <cfelse>

                ''

            </cfif>

    <cfelse>

              ''

    </cfif>

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 11, 2012 5:39 PM   in reply to jlig

    Regarding:

    I'm not sure how to "tie" the tblUsers (where the email address is) to the tblTickets (where the ttType is) and only send those people the email..

     

    Neither am I because I am not familiar with your database.  This is a rather long thread in which the topic has changed.  My suggestion is to start a new one that focuses on this particular problem.  Provide as much information about your database as you deem relevent.  Look for a table that has both a user id and a ticket id.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 12, 2012 12:06 AM   in reply to Dan Bracuk

    Dan Bracuk wrote:

     

    Neither am I because I am not familiar with your database.  This is a rather long thread in which the topic has changed.  My suggestion is to start a new one that focuses on this particular problem.

    Hyear, hyear.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points