CartThrob 9 documentation for ExpressionEngine commerce teams Visit CartThrob.com
CartThrob.com

State Select

state_select outputs an HTML <select> of states/regions from CartThrob locales data.

To edit the state list, see Locales Config.

See also:

Parameters

abbrev_label

Use state abbreviations as option labels.

Default: no (full state names as labels).

abbrev_label="yes"

abbrev_value

Use state abbreviations as option values.

Default: yes.

abbrev_value="yes"

selected

Currently selected state value.

selected="{customer_state}"

default

Fallback selected state when selected is not provided.

default="CA"

country_code

Country code(s) used to determine which state list to output.

If omitted, locale default_state_country is used. Pipe-delimited codes are supported by the locales lookup.

country_code="USA"

country_code="USA|CAN"

name

Name attribute of the generated <select>.

Default: state.

name="state"

extra

Additional raw HTML attributes appended to the <select>.

extra='data-role="state-select" aria-label="State"'

id

id attribute for the <select>.

id="state"

class

class attribute for the <select>.

class="state-select"

onchange

Inline JavaScript onchange attribute.

onchange="this.form.submit()"

add_blank

Adds a blank --- option at the top.

add_blank="yes"

Output

Returns an HTML <select> element.

Option label/value format depends on abbrev_label and abbrev_value.

Behavior and Constraints

  1. State options come from ee()->locales->states(country_code).
  2. If country_code is omitted, locale default_state_country is used.
  3. selected takes precedence; default is used only as fallback.
  4. abbrev_label and abbrev_value control whether labels/values use abbreviations or full names.
  5. id, class, onchange, and extra are passed through to the generated <select>.

Examples

Basic usage:

{exp:cartthrob:state_select name="state" selected="{customer_state}"}

Shipping state field:

{exp:cartthrob:state_select
    name="shipping_state"
    id="shipping_state"
    selected="{customer_shipping_state}"
    add_blank="yes"
}

Use abbreviations for labels and values:

{exp:cartthrob:state_select
    name="state"
    abbrev_label="yes"
    abbrev_value="yes"
    selected="MO"
}