Hi Gil,
Sorry took long to respond
here is the full code i had and its working.
the problem is need to do the switch code inside the do while loop
add_filter("gform_pre_render", "process_unique");
function process_unique($form) {
global $uuid;
$uuid['form_id'] = $form['id'];
switch($form['id']) {
case 6: //form ID
$uuid['field_id'] = 60; //field ID on the form
break;
case 14: //form ID
$uuid['field_id'] = 158; //field ID on the form
break;
case 12: //form ID
$uuid['field_id'] = 158; //field ID on the form
break;
case 11: //form ID
$uuid['field_id'] = 34; //field ID on the form
break;
case 13: //form ID
$uuid['field_id'] = 28; //field ID on the form
break;
case 16: //form ID
$uuid['field_id'] = 2; //field ID on the form
break;
case 10: //form ID
$uuid['field_id'] = 49; //field ID on the form
break;
case 4: //form ID
$uuid['field_id'] = 30; //field ID on the form
break;
case 1: //form ID
$uuid['field_id'] = 34; //field ID on the form
break;
case 5: //form ID
$uuid['field_id'] = 49; //field ID on the form
break;
case 7: //form ID
$uuid['field_id'] = 60; //field ID on the form
break;
case 8: //form ID
$uuid['field_id'] = 33; //field ID on the form
break;
case 3: //form ID
$uuid['field_id'] = 29; //field ID on the form
break;
case 2: //form ID
$uuid['field_id'] = 5; //field ID on the form
print_r('aaa');
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'];
global $wpdb;
do {
$formid = $form_id; //get ID of the form
switch($form_id) {
case 6:
$prefixs = "FOHSRF # - "; //prefixs for different forms
break;
case 14:
$prefixs = "VSRF # - "; //prefixs for different forms
break;
case 12:
$prefixs = "VSRF # - "; //prefixs for different forms
break;
case 11:
$prefixs = "VSDEIF # - "; //prefixs for different forms
//print_r($prefixs);
break;
case 13:
$prefixs = "FOHSRLR # - "; //prefixs for different forms
break;
case 10:
$prefixs = "SMRF # - "; //prefixs for different forms
break;
case 4:
$prefixs = "VTTCF # - "; //prefixs for different forms
break;
case 1:
$prefixs = "EHF # - "; //prefixs for different forms
break;
case 5:
$prefixs = "ELA # - "; //prefixs for different forms
break;
case 7:
$prefixs = "IRF # - "; //prefixs for different forms
break;
case 8:
$prefixs = "SIF # - "; //prefixs for different forms
break;
case 3:
$prefixs = "RIF # - "; //prefixs for different forms
break;
case 16:
$prefixs = "GHIRA # - "; //prefixs for different forms
break;
case 2:
$prefixs = "CSF wewwe# - "; //prefix for different forms
break;
}
$tables = $wpdb->prefix . 'rg_lead';
$form_count = $wpdb->get_var("SELECT COUNT(*) FROM $tables WHERE form_id = '$formid'");
//$date = date("d/m/Y");
//$form_count = RGFormsModel::get_form_counts($formid);
$unique = $form_count + 1; // 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
$date = date('m-d-Y');
//print_r($date);
$unique = $prefixs . $unique . ' - ' . $date; // prefixs and the unique number //
} while (!check_unique($unique, $form_id, $field_id));
//print_r($unique);
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;
}
Posted 11 years ago on Thursday February 21, 2013 |
Permalink