How to set a `selected` with Select(objectName) ?

20 views
Skip to first unread message

kristof polleunis

unread,
Nov 12, 2012, 1:56:41 AM11/12/12
to cfwh...@googlegroups.com
The site runs on Nginx with Tomcat and Nginx has the geoip module enabled.   So I can get the country of the visitor as cgi variable in CFWheels.  Now I have a select list of countries with value equals to a two character iso-countrycoded.  I would like it to be set to the country detected.

#select(objectName="user", id="country", property="country", options=countrylist)#
#errorMessageOn(objectName="user", property="country")#

What I would like to have if let's say the countrycode from the cgi variable is AQ that Antartica is set default.

<select id="country" name="user[country]">
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
<option value="AS">American Samoa</option>
<option value="AD">Andorra</option>
<option value="AO">Angola</option>
<option value="AI">Anguilla</option>
<option value="AQ" selected>Antarctica</option>
<option value="AG">Antigua and Barbuda</option>
<option value="AR">Argentina</option>
<option value="AM">Armenia</option>
...
</select>

Yannick Morin

unread,
Nov 12, 2012, 6:28:19 AM11/12/12
to cfwh...@googlegroups.com
You can do something like this in your controller:

<cfset user = model("User").new()>

<cfset user.country = cgi.iso-countrycoded>



--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/pcfOqClG0CwJ.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.

kristof polleunis

unread,
Nov 12, 2012, 8:07:35 AM11/12/12
to cfwh...@googlegroups.com
Thanks Yannick that works beautifully

Op maandag 12 november 2012 12:28:41 UTC+1 schreef Yannick Morin het volgende:

Yannick Morin

unread,
Nov 12, 2012, 8:33:26 AM11/12/12
to cfwh...@googlegroups.com
Glad  I could help.


To view this discussion on the web visit https://groups.google.com/d/msg/cfwheels/-/2xr5T4uVqEEJ.
Reply all
Reply to author
Forward
0 new messages