Advertisement
Guest User

Random Number Function

a guest
Apr 26th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. add_filter("gform_field_value_uuid", "get_unique");
  2.  
  3. function get_unique(){
  4.  
  5.     $prefix = "CF"; // update the prefix here
  6.  
  7.     do {
  8.         $unique = mt_rand();
  9.         $unique = substr($unique, 0, 8);
  10.         $unique = $prefix . $unique;
  11.     } while (!check_unique($unique));
  12.  
  13.     return $unique;
  14. }
  15.  
  16. function check_unique($unique) {
  17.     global $wpdb;
  18.  
  19.     $table = $wpdb->prefix . 'rg_lead_detail';
  20.     $form_id = 28; // update to the form ID your unique id field belongs to
  21.     $field_id = 2; // update to the field ID your unique id is being prepopulated in
  22.     $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
  23.  
  24.     if(empty($result))
  25.         return true;
  26.  
  27.     return false;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement