Advertisement
princeofheart

Gravity

May 8th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2. add_filter("gform_pre_render", "process_unique");
  3. function process_unique($form) {
  4. global $uuid;
  5. $uuid['form_id'] = $form['id'];
  6. switch($form['id']) {
  7. case 24: //form ID
  8. $uuid['field_id'] = 10; //field ID on the form
  9. break;
  10.  
  11. }
  12. add_filter("gform_field_value_uuid", "get_unique");
  13. return $form;
  14. }
  15. function get_unique(){
  16. global $uuid;
  17. $form_id = $uuid['form_id'];
  18. $field_id = $uuid['field_id'];
  19. switch($form['id']) {
  20. case 24:
  21. $prefix = "P # - "; //prefix for different forms
  22. break;
  23. }
  24. do {
  25. $formid = $form_id; //get ID of the form
  26. $form_count = RGFormsModel::get_form_counts($formid);
  27. $unique = $form_count['total'] + 205; // count of the lead form entries incremented by one
  28. $unique = str_pad($unique, 3, '0', STR_PAD_LEFT); // padding for number format 001,002...015 so 3 digit number format
  29. $unique = $prefix . $unique; // prefix and the unique number
  30. } while (!check_unique($unique, $form_id, $field_id));
  31. return $unique;
  32. }
  33. function check_unique($unique, $form_id, $field_id) {
  34. global $wpdb;
  35. $table = $wpdb->prefix . 'rg_lead_detail';
  36. $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
  37. if(empty($result))
  38. return true;
  39. return false;
  40. }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement