I am attempting to use this example:
https://formidableforms.com/knowledgebase/formidable_shortcode_atts/
add_action('formidable_shortcode_atts', 'frm_admin_readonly', 20, 2);
function frm_admin_readonly( $atts, $all_atts ) {
if ( $atts['readonly'] == 'administrator' ) {
global $frm_vars;
if ( current_user_can('administrator') ) {
$frm_vars['readonly'] = 'disabled';
} else {
$frm_vars['readonly'] = false;
}
}
}
but I want it to apply to more than just administrators. So, I created code like this (following the documentation):
https://formidableforms.com/knowledgebase/formidable-hooks/#kb-duplicating-a-function
add_action('formidable_shortcode_atts', 'frm_admin_readonly1', 20, 2);
function frm_admin_readonly1( $atts, $all_atts ) {
if ( $atts['readonly'] == 'administrator' ) {
global $frm_vars;
if ( current_user_can('administrator') ) {
$frm_vars['readonly'] = 'disabled';
} else {
$frm_vars['readonly'] = false;
}
}
}
add_action('formidable_shortcode_atts', 'frm_admin_readonly2', 20, 2);
function frm_admin_readonly2( $atts, $all_atts ) {
if ( $atts['readonly'] == 'second-group' ) {
global $frm_vars;
if ( current_user_can('second-group') ) {
$frm_vars['readonly'] = 'disabled';
} else {
$frm_vars['readonly'] = false;
}
}
}
I have used this pattern on Hooks before and it worked just fine. I also tried this:
add_action('formidable_shortcode_atts', 'frm_admin_readonly1', 20, 2);
function frm_admin_readonly1( $atts, $all_atts ) {
if ( $atts['readonly1'] == 'administrator' ) {
global $frm_vars;
if ( current_user_can('administrator') ) {
$frm_vars['readonly1'] = 'disabled';
} else {
$frm_vars['readonly1'] = false;
}
}
}
add_action('formidable_shortcode_atts', 'frm_admin_readonly2', 20, 2);
function frm_admin_readonly2( $atts, $all_atts ) {
if ( $atts['readonly2'] == 'second-group' ) {
global $frm_vars;
if ( current_user_can('second-group') ) {
$frm_vars['readonly2'] = 'disabled';
} else {
$frm_vars['readonly2'] = false;
}
}
}
and some other combinations. Then updated my shortcode to read:
[formidable id="3" readonly='administrator' readonly='second-group']
but this is not working. I also tried combinations for the shortcode to match my changes in the filter above like this:
[formidable id="3" readonly1='administrator' readonly2='second-group']
[formidable id="3" readonly='administrator,second-group']
When I use the example and restrict it to only the 'administrator' user, it does work, but every combination of code I have tried will not allow me to apply this to another user type. I have tried a lot of combinations. Can this be done? Does it only work for a single user role? Admins only? I feel it is something simple that I am missing, but Formidable Support defines it as "custom code". I'm happy to pay for someone to code it, despite thinking that I simply have the wrong combination of instance numbers in place.
Thanks!
Hey Rob!
Thanks for your thoughts. Generally speaking, I try to follow the Formidable guides for items like this. In the past, I have used multiple instances with good success, but I have not seen any documentation on using, or editing a function by using an array. Formidable is great, but one of their weak spots is their documentation. It is very complete, but sometimes not well organized.
I will give your code sample a try and if I have no luck, I'd be happy to get you to do it. I'll follow up with my results.
Much appreciated!!!
Vince
OK sounds good. I'm 99% sure the page about the duplicating of a function is meant for cases where someone has multiple features or forms that they want to keep things separate. In your case, it's all one happy family and it makes organizational sense to do it in one function. To be clear, it'll work if you do it in multiple functions, it's just that I will have to come after you with my cooking skillet and beat you with it.
Ha! Not the skillet!!! I will be on my best behavior 🙂
I think we're to the point where you're going to need to hire me if you want to move forward. I'm pretty cheap as things go (hourly) and I don't charge if I don't fix it. You can send me a message via the forums if you want to discuss it. https://connect.formidableforms.com/messages
@Vince Dimanno: You're experiencing a common issue with AJAX and the HTML DOM. jQuery works only on fields that exist in the DOM when the page is loaded. AJAX adds fields on the fly, so jQuery needs to be reinitialized for every new repeater row. This is how you fix it: https://formidable-masterminds.com/repeaters-and-complex-jquery-operations/
Thanks Victor!
Please login or Register to submit your answer