Copy link to clipboard
Copied
Hello;
I am writting a small contact form. I want to use cfselect so it will be populated with all the states.I have it working fine, my problem is, when the email is sent from the form, it sends the ID of the state, not the actual state name.I am trying to write an if statement to compair the form.state to the record id in the DB and then when it sends the email, it sends the actual state name in the matched db record.
this is my code, it is pretty simple and strait forward.
Contact page
<cfquery name="SESSION.stat" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
SELECT state, ID
FROM States
</cfquery>
<cfform......>
<cfselect enabled="No" name="state" size="1" class="selectstyle" required="yes" message="Please enter your state!" multiple="no" queryPosition="below">
<option value="" selected>--Select a State--</option>
<CFOUTPUT query= "SESSION.stat">
<option value="#ID#">#state#</option>
</CFOUTPUT></cfselect>
</cfform>
Response page:
<cfquery name="SESSION.stat" datasource="#APPLICATION.dataSource#" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#">
SELECT state, ID
FROM States
</cfquery>
<cfmail to="me@mywebsite.com
from="#form.email#"
subject="web siteRequest"
server="mail.myhost.com"
port=25
type="HTML">
<font face="Verdana, Arial, Helvetica, sans-serif" color="##000000" size="2">
<b>Status:</b> <b>Request!!</b><br>
<!--- this is my error query --->
<cfoutput query="stat">
C <b>Customer State:</b> #state#<br>
</cfif>
</cfoutput>
</cfmail>
I think need to fix
<cfif form.state EQ ('#ID#')>
<b>Customer State:</b> #state#<br>
</cfif>
this is not working properly, and i forget how to compare the orm submission to the DB record. Can anyone help me out?
thank you.
CFmonger
Copy link to clipboard
Copied
Make the value of your cfselect the state instead of the id.
Copy link to clipboard
Copied
I knew I wasn't thinking right. That did it!
I have a loaded question for you now....
how do you make the cfselect a required field like the other fields so it comes up in the cf-generated java validation code? I have been reading you can only do this by overriding it with it's own java script. Is this true?I do have validation working for it on the server sided response page, just not in the field validation required=Yes" messge="You didn't choose fool!" doesn't work.
Any ideas that do work?
Thank you.
Copy link to clipboard
Copied
Making a select control required is redundant because a value is always submitted. If it's a value you don't want, you can write some javascript to check.
Copy link to clipboard
Copied
Yeah, that's what I read. Thanks for the help!