Skip to content

Commit

Permalink
gpuid-sequence-by-prefix.php: Added new snippet.
Browse files Browse the repository at this point in the history
  • Loading branch information
spivurno authored Dec 9, 2023
1 parent f61d124 commit 7d2c18d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gp-unique-id/gpuid-sequence-by-prefix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Gravity Perks // Unique ID // Sequence by Prefix
* https://gravitywiz.com/path/to/article/
*
* Create unique sequences based on the generated prefix. For example, if you have a Drop Down field where the user
* can select A, B, or C, and you set the prefix of your Unique ID field to the merge tag of this Drop Down field, this
* snippet will then treat each value as a unique sequence (e.g. A00001, A00002, B00001, A00003, B00002, etc).
*/
// Update "123" to your form ID and "4" to your Unique ID field ID.
add_filter( 'gpui_unique_id_attributes_123_4', function ( $atts, $form_id, $field_id, $entry ) {

$prefix = (int) GFCommon::replace_variables( $atts['prefix'], GFAPI::get_form( $form_id ), $entry, false, true, false, 'text' );

$atts['slug'] = "seq-by-prefix-{$prefix}";

return $atts;
}, 10, 4 );

0 comments on commit 7d2c18d

Please sign in to comment.