admin管理员组文章数量:1130349
I have multiple forms. Based on those forms I need a hidden field populated with a prefix and a sequential number. Each form has a hidden field. That field can be filled dynamically and has a paramater of 'uuid'.
I have the following code... any suggestions on how to change the following code? This snippet works but it uses a random number (mt_rand), I prefer [prefix]-00001, [prefix]-00002, etc.
In addition it would be even better when every form has his own prefix. But that beyond my php skills. Preferably sequential for every form, example:
Form A with a prefix 'prd' ([prefix]-00001)
- prd-00001
- prd-00002
Form B with a prefix 'lead' ([prefix]-00001)
- lead-00001
- lead-00002
Thanks for any thoughts and ideas. Keep in mind that my php skills are pretty basic.
Paul
add_filter("gform_field_value_uuid", "get_sequential_nr");
function get_sequential_nr(){
$prefix = "set_prefix_here";
do {
$unique = mt_rand();
$unique = substr($unique, 0, 5);
$unique = $prefix . $unique;
} while (!check_unique_nmbr($unique));
return $unique;
}
function check_unique_nmbr($unique) {
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;
}
I have multiple forms. Based on those forms I need a hidden field populated with a prefix and a sequential number. Each form has a hidden field. That field can be filled dynamically and has a paramater of 'uuid'.
I have the following code... any suggestions on how to change the following code? This snippet works but it uses a random number (mt_rand), I prefer [prefix]-00001, [prefix]-00002, etc.
In addition it would be even better when every form has his own prefix. But that beyond my php skills. Preferably sequential for every form, example:
Form A with a prefix 'prd' ([prefix]-00001)
- prd-00001
- prd-00002
Form B with a prefix 'lead' ([prefix]-00001)
- lead-00001
- lead-00002
Thanks for any thoughts and ideas. Keep in mind that my php skills are pretty basic.
Paul
add_filter("gform_field_value_uuid", "get_sequential_nr");
function get_sequential_nr(){
$prefix = "set_prefix_here";
do {
$unique = mt_rand();
$unique = substr($unique, 0, 5);
$unique = $prefix . $unique;
} while (!check_unique_nmbr($unique));
return $unique;
}
function check_unique_nmbr($unique) {
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;
}
Share
Improve this question
edited Aug 1, 2018 at 12:29
Kortschot
asked Aug 1, 2018 at 12:22
KortschotKortschot
1171 silver badge7 bronze badges
1 Answer
Reset to default 0Have you looked at the Gravity Forms Unique ID Wiz? This allows you to specify a prefix for each form that gets added to the Entry ID.
I have multiple forms. Based on those forms I need a hidden field populated with a prefix and a sequential number. Each form has a hidden field. That field can be filled dynamically and has a paramater of 'uuid'.
I have the following code... any suggestions on how to change the following code? This snippet works but it uses a random number (mt_rand), I prefer [prefix]-00001, [prefix]-00002, etc.
In addition it would be even better when every form has his own prefix. But that beyond my php skills. Preferably sequential for every form, example:
Form A with a prefix 'prd' ([prefix]-00001)
- prd-00001
- prd-00002
Form B with a prefix 'lead' ([prefix]-00001)
- lead-00001
- lead-00002
Thanks for any thoughts and ideas. Keep in mind that my php skills are pretty basic.
Paul
add_filter("gform_field_value_uuid", "get_sequential_nr");
function get_sequential_nr(){
$prefix = "set_prefix_here";
do {
$unique = mt_rand();
$unique = substr($unique, 0, 5);
$unique = $prefix . $unique;
} while (!check_unique_nmbr($unique));
return $unique;
}
function check_unique_nmbr($unique) {
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;
}
I have multiple forms. Based on those forms I need a hidden field populated with a prefix and a sequential number. Each form has a hidden field. That field can be filled dynamically and has a paramater of 'uuid'.
I have the following code... any suggestions on how to change the following code? This snippet works but it uses a random number (mt_rand), I prefer [prefix]-00001, [prefix]-00002, etc.
In addition it would be even better when every form has his own prefix. But that beyond my php skills. Preferably sequential for every form, example:
Form A with a prefix 'prd' ([prefix]-00001)
- prd-00001
- prd-00002
Form B with a prefix 'lead' ([prefix]-00001)
- lead-00001
- lead-00002
Thanks for any thoughts and ideas. Keep in mind that my php skills are pretty basic.
Paul
add_filter("gform_field_value_uuid", "get_sequential_nr");
function get_sequential_nr(){
$prefix = "set_prefix_here";
do {
$unique = mt_rand();
$unique = substr($unique, 0, 5);
$unique = $prefix . $unique;
} while (!check_unique_nmbr($unique));
return $unique;
}
function check_unique_nmbr($unique) {
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;
}
Share
Improve this question
edited Aug 1, 2018 at 12:29
Kortschot
asked Aug 1, 2018 at 12:22
KortschotKortschot
1171 silver badge7 bronze badges
1 Answer
Reset to default 0Have you looked at the Gravity Forms Unique ID Wiz? This allows you to specify a prefix for each form that gets added to the Entry ID.
本文标签: functionsAdd sequential number to a Gravityforms form
版权声明:本文标题:functions - Add sequential number to a Gravityforms form 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749226038a2335621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论