In some cases, it’s useful to use a select field to determine what kind of records will be shown in a grid elsewhere on the page.
Use the pzSelectControl block to make this work. Within the block, you select the table and filter field you’ll control with the block. You might select the Person table, for example, and chose the “pz_level” field as the filtering value.
You can then select whether you want to use all the existent values stored for the chosen field (that is, in the example above, you’d use every value that had been used in the pz_level field to that point) or, alternately, whether you want to explicitly list which values you’ll allow as filters.
You can check the box to include an “Add New” option to the select options.
If you’re entering explicit values, you do this in the editable section of the block, adding as many values as you’d like.
To take another example, you might pick the “pz_function” table and the “function_name” field, choosing to show the “Add New” option to allow users to create new pzFunctions.
The select control block is placed outside of the primary form on the page and it operates independently. It responds as soon as the value of the select option is changed. It’s action is to reload the page, adding a URL parameter that tells the elements on the form you’ve placed on the page which data to display.
One use scenario is controlling a grid display and limiting it to certain categories. So you might, for example, have an option in your group that was set to the value of “agents.” When that option was selected, the page would be reloaded with the fieldname you’d chosen to control with as a parameter set to the value “agents”.
Elsewhere on the page, a grid displaying persons would then filter and display on the “agents” value.
A second use scenario is to select a specific record value. For instance, you might have a select control group that showed the names of all the pzFunctions in use on your site (as discussed above). When a name is selected the page redirection occurs and the form shows the fields from the record whose name matches the radiobutton selection.
This is, in fact, exactly how the automatically generated PZ Functions page works and you can have a look at it as a working example of how this use case works.
Note that both the form block and various grid blocks automatically detect that the control parameter is in use and adjust their display and operation without you needing to change any settings within them.
DO KEEP SECURITY IMPLICATIONS IN MIND… As often as not, pages using the select control block will be pages that are restricted (by the pzAccess block) to admin users.
The potential risk for pages that are generally available is that malicious users might guess a value that isn’t among the options you are offering in the select dropdown and the data will be displayed in the form or grid.
So it’s clearly not a good idea to use this technique and filter using a subset of the options stored in a field, if the other options are confidential in some way. Don’t let users pick “blue services” or “green services” if there’s also a “red services” category that they should not have access to. If they guess “red services” exists and fake the variable used for the page reload, they’ll be able to see that category. (For that kind of situation, you’ll probably need to write at least a little custom code or use a separate plugin for fine-grained page access control.)