Subscription Select
Outputs a dropdown for subscription options. Inside an add_to_cart_form or update_cart_form, CartThrob discovers its allowed values and signs them for that form. Encryption of option values alone does not authorize a change.
A fixed parameter on the enclosing form wins over a selector. A nonblank posted value outside the signed set stops the add or update with a validation error. Undeclared protected values are still ignored. A form-tag options: declaration replaces this selector’s list for the same key; declare each term in one place. Selectors in embeds or with PHP-built options need an explicit options:<param> declaration on the form; see Customer-selectable values. These selectors configure cart items, not existing paid Subscriptions.
Parameters
name
Subscription setting to select. Defaults to subscription_interval_units; the generated field uses the corresponding protected key, such as SIU for units or SUB for the recurring yes/no choice.
Common values include:
subscription_interval_unitssubscription_interval_lengthsubscription_end_datesubscriptionsubscription_total_occurrencessubscription_plan_id
options
Pipe-delimited options to encode and declare as allowed values. Defaults to days|weeks|months|years. Only values before the colon are signed; labels are for display.
For subscription_interval_units and subscription_trial_interval_units, each value must be one of days, weeks, months or years. Put a singular or friendly name in the label instead, for example months:month or months:Monthly. See Billing intervals.
options="days|weeks|months|years"
Label overrides are supported with value:label syntax.
options="months:Monthly|years:Yearly"
selected
Selected option value.
default
Fallback selected value.
row_id
Scopes the input to this cart row: for example, name="subscription_interval_length" row_id="{row_id}" generates SI[{row_id}]. Use it on every selector inside a cart-item loop. When selected/default are missing, the dropdown uses subscription metadata from this row (if available).
add_blank
yes/no. When truthy, prepends a blank option labeled ---.
id
HTML id attribute.
class
HTML class attribute.
onchange
HTML onchange attribute.
extra
Additional raw attributes appended to the <select>.
Notes
- For
name="subscription_plan_id", plan options are resolved against available plans, but Plan identity is not declared as a customer-selectable protected value. Use the Plan purchase workflow instead. Plan rows keep their Plan billing terms when the cart is updated. - For
name="subscription", the generated field name is internally mapped toSUB.
Example
{exp:cartthrob:subscription_select
name="subscription_interval_units"
options="days|months"
selected="{interval_units}"
class="form-select"
}
Requiring a choice
required= on the enclosing form checks the posted field name, and this selector posts the term’s short key, not its readable name. To make a selector’s choice required, list the short key: required="SI", not required="subscription_interval_length". Don’t list the readable name. required= then names a field this selector never posts, so the form is always refused with “This field is required”, even when the customer has chosen.
name= on the selector |
Posted field | In required= |
|---|---|---|
subscription |
SUB |
SUB |
subscription_interval_length |
SI |
SI |
subscription_interval_units |
SIU |
SIU |
subscription_total_occurrences |
SO |
SO |
subscription_trial_occurrences |
SP |
SP |
subscription_trial_interval_length |
STIL |
STIL |
subscription_trial_interval_units |
STIU |
STIU |
subscription_end_date |
SED |
SED |
{exp:cartthrob:add_to_cart_form entry_id="{entry_id}" subscription="yes" required="SI|SIU"}
{if errors_exist}
{errors}<p class="alert alert-error">{error}</p>{/errors}
{/if}
{exp:cartthrob:subscription_select name="subscription_interval_length" options="1|3|12" add_blank="yes"}
{exp:cartthrob:subscription_select name="subscription_interval_units" options="months|years" add_blank="yes"}
<button type="submit">Subscribe</button>
{/exp:cartthrob:add_to_cart_form}
With row_id, the field is the short key with the row, such as SI[{row_id}], and required= names that field. Readable names in required= work only for hand-written fields that post under the readable name. Render {errors} inside an {if errors_exist} block on the form so rejected and missing choices are visible.
A value that isn’t in the declared list stops the whole add or cart update with “Choose valid subscription options.”, and the field gets “Choose a valid option.” Nothing in the cart changes. The same error appears when a selector’s encrypted value no longer decrypts, for example a page cached before the store’s encryption key changed; reloading the form fixes it.
Typed values and ranges
This selector declares a list. For a hand-written field that accepts a range or any valid value, use a rule on the enclosing form, such as options:subscription_interval_length="1-24". A form-tag rule replaces the selector’s list; rules accept plain values only, so use your own input rather than this selector’s encrypted options. See lists, ranges and typed values for eligible terms and limits.