Filter form field on task

By: Iris van Zelderen | Asked: 08/26/2022
ForumsCategory: Code SnippetsFilter form field on task
Iris van Zelderen asked 2 years ago
Hi!
We have a form field where we want to only show the members who have a special task. So, for example, the Kassa field we only want the people who have a task to operate the Kasse.
I\'m not sure if you can see the link, because it's only for logged in people. I have an attached file here as well. We did have a PHP snippet who made it possible, but if I activate this we have a fatal error on the forms.  (*I can't upload a PHP file here, so see in the bottom off this message)
So can you look why the PHP snippet is not working or how we can make this work?
Thanks already!


Form Link: https://lingefilm.nl/vrijwilligers/dienstrooster/aanpassen/?frm_action=edit&entry=4350
WP Version: 6.0.1
Formidable Version: 5.4.4   PHP file: <?php
/** * Filter vrijwilliger op taak */ add_filter('frm_setup_new_fields_vars', 'filter_dfe_options', 25, 2); add_filter('frm_setup_edit_fields_vars', 'filter_dfe_options', 25, 2); function filter_dfe_options($values, $field){ if ( $field->id == 112 && !empty( $values['options'] ) ) { // Het selectieveld Monteren $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Operateur') !== false ) ) // Only include values where filtering field includes "Operateur" { continue; } unset( $values['options'][$id] ); } } if ( $field->id == 141 && !empty( $values['options'] ) ) { // Het selectieveld Monteren - assistent $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Operateur') !== false ) ) // Only include values where filtering field includes "Operateur" { continue; } unset( $values['options'][$id] ); } } if ( $field->id == 113 && !empty( $values['options'] ) ) { // Het selectieveld Operateur $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Operateur') !== false ) ) // Only include values where filtering field includes "Operateur" { continue; } unset( $values['options'][$id] ); } } if ( $field->id == 143 && !empty( $values['options'] ) ) { // Het selectieveld Operateur - assistent $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Operateur') !== false ) ) // Only include values where filtering field includes "Operateur" { continue; } unset( $values['options'][$id] ); } } if ( $field->id == 114 && !empty( $values['options'] ) ) { // Het selectieveld Kassa $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Kassa') !== false ) ) // Only include values where filtering field includes "Kassa" { continue; } unset( $values['options'][$id] ); } } if ( $field->id == 144 && !empty( $values['options'] ) ) { // Het selectieveld Kassa - assistent $temp = $values; $temp['form_select'] = 125; //change to the id of the field (in linked form) that you want to filter by $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field ); foreach ( $values['options'] as $id => $v ) { if ( isset( $field2_opts[$id] ) && ( $v == '' || strpos($field2_opts[$id],'Kassa') !== false ) ) // Only include values where filtering field includes "Kassa" { continue; } unset( $values['options'][$id] ); } } return$values; }  
Attachments
3 Answers
Walter JonesWalter Jones answered 2 years ago
Just for simplicity’s sake, your trying to hide a field based on a users role on your Wordpress site or how are you determining that the user has a “special task”?
Iris van Zelderen answered 2 years ago
Hi Walter, I think you need a little more explanation. This form serves as a duty roster. So that the people who work for this art house know what to do. One person is responsible for the "Monteren" and the other for the "Kassa". The form is filled out by someone who only wants to see the names that can actually perform this task. So for example MartinK can only do the "Monteren" while Jules can do both "Monteren" and the "Kassa". Do you understand?  
Walter JonesWalter Jones answered 2 years ago
Why don’t you just build a search form and pass the parameters through a view? Then someone can search for the task and the view will show who that task is assigned too. 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right