Skip to main content
Ungathered Thoughts

CiviCRM Contribute Form JS: Don't Rely on Priceset IDs.

Since a lot of CiviCRM work is around supporter donations / memberships, at Fuzion we end up doing quite a lot of customisation. It's tempting when writing stylesheets and javascript to depend on the IDs and values provided in the page, but with CiviCRM this can lead to trouble down the track.

CiviCRM manages price sets internally as a list of values in a DB table, and the assigned IDs for each price option may change if the priceset is edited. This can mean that a client change on a live site breaks a customisation that was previously working, for no reason other than them changing a different price on the same form.

Where possible, try to check something which is not one of CiviCRM's autogenerated IDs relating to the priceset or the priceset value (=id of that price option). The above change is hardly any better - if someone changes "3 years" to "3 yrs" it'll still break, but at least it's more tied to the actual criteria we're checking than an ephemeral id from the database.