Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter("gform_pre_render", "process_unique");
- function process_unique($form) {
- global $uuid;
- $uuid['form_id'] = $form['id'];
- switch($form['id']) {
- case 24: //form ID
- $uuid['field_id'] = 10; //field ID on the form
- break;
- }
- add_filter("gform_field_value_uuid", "get_unique");
- return $form;
- }
- function get_unique(){
- global $uuid;
- $form_id = $uuid['form_id'];
- $field_id = $uuid['field_id'];
- switch($form['id']) {
- case 24:
- $prefix = "P # - "; //prefix for different forms
- break;
- }
- do {
- $formid = $form_id; //get ID of the form
- $form_count = RGFormsModel::get_form_counts($formid);
- $unique = $form_count['total'] + 205; // count of the lead form entries incremented by one
- $unique = str_pad($unique, 3, '0', STR_PAD_LEFT); // padding for number format 001,002...015 so 3 digit number format
- $unique = $prefix . $unique; // prefix and the unique number
- } while (!check_unique($unique, $form_id, $field_id));
- return $unique;
- }
- function check_unique($unique, $form_id, $field_id) {
- global $wpdb;
- $table = $wpdb->prefix . 'rg_lead_detail';
- $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
- if(empty($result))
- return true;
- return false;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement