Personal tools
Home Webmaster Resources Zope/Plone Plone Country Selector

Plone Country Selector

At some point, you might find it useful to add a Country select field to a form.  This is especially handy when you need to extend the "Personal Preferences" form in Plone.

The first step is to download the availableCounties python script below.

Place this code on the file system at:   /zope_instance/Products/CMFPlone/skins/plone_scripts

If you don't have access to the file system, you can drop this file in your portal_skins/custom folder.


Then you can customize personalize_form in portal_skins/plone_prefs and add the following code:

           <div class="field"
                 tal:define="error errors/country | nothing;
                             country python:request.get('country', member.getProperty('country', ''));"
                 tal:attributes="class python:test(error, 'field error', 'field')">

                <label for="country" i18n:translate="label_country">Country</label>

                <div class="formHelp" i18n:translate="help_preferred_country">
                Your Country
                </div>

                <div tal:content="error">Validation error output</div>


                <select name="country"
                        id="country"
                        tabindex=""
                        tal:attributes="tabindex tabindex/next;">
                    <tal:block tal:repeat="cntry here/availableCountries">
                        <option value="None"
                            tal:content="python:cntry[1]"
                            tal:attributes="value python:cntry[0];
                                            selected python:test(country==cntry[0], 'selected', None);">
                        </option>
                    </tal:block>
                 </select>


You may also want to do this for the join form at portal_skins/plone_login.

Need assistance with your project? Universal Web Services can help.
Contact us to request a quote.

Related content