Select Page

Auto-increment ID in Formidable forms

Formidable Forms [auto_id] shortcode is used to set an unique and auto-incrementing value to form entries. Example usecases include serial number, job number and invoice number.

By default, numbers start from 1 but it can be changed with “start” attribute.
e.g. [auto_id start=1000]

A prefix and/or suffix can be added by simply adding letters before and/or after the shortcode.
e.g. SN[auto_id start=1000]A
This will generate SN1000A, SN1001A, SN1002A, .... and so on.

One of the limitations of the shortcode is, prefix/suffix can’t have numbers. If numbers included, it could result in unexpected values. However, adding zeros as the prefix will work since leading zeros have no effect on a number. We might tempt to use it generate a serial number with a fixed number of digits like 001, 002, 003, … using 00[auto_id]. But the issue is after 10, it will become 0010 instead of 010. In order to dynamically add leading zeros, following custom code can be used.

add_filter('frm_pre_create_entry', 'format_auto_number');
function format_auto_number($values){
  if ( $values['form_id'] == 27 ) {//Replace 27 with your Form ID
    //Replace 126 with your field ID.
    //Here 3 in sprintf function represents number of fixed digits.
    $values['item_meta'][126] = sprintf("%03d", $values['item_meta'][126]);
  }
  return $values;
}