Hello everyone, I will briefly explain my situation:
I have a custom module that has a field related to the Users module, what I would like to do is to set an initial filter that shows the list of a certain group of users, so far so good, in editviewdefs.php of the custom module I set the initial filter via:
now when the popup window opens, the related field appears set with the initial_filter value, the problem is that if this field is changed of course the filter is applied to the whole Users form. If I remove the Users field from the filter, it works only when I open the popup, but if I click on the “search” button, without setting anything, it shows me the list of all users, losing the initial filter.
Any ideas on how to fix this please? Thanks
but in this case it doesn’t work,
1, because $tmp['field_to_name_array']['name'] is empty, not even $this->_focus->name collects anything;
2, since it is a relate field, if in $where_param I insert the relate field, it doesn’t recognize it
Yes, now I’m working with popups, above I described how I solved a similar problem, but in that case I was working with subpanels and I thought I could solve it in the same way, but I couldn’t.
$_REQUEST[‘name_advanced’] works only the first time I open the popup, then, if I click on the search button without setting anything, it empties out
in the file custom/modules//metadata/editviewdefs there is this:
Code for custom/modules/<module_name_2>/metadata/popupdefs.php:
if(!empty($_REQUEST['<field_relate>_name_advanced'])){
$parametrs_advanced='`<field_relate>_name`="'.$_REQUEST['<field_relate>_name_advanced'].'"'; // example part of SQL WHERE
$_REQUEST['request_data']=json_encode(htmlentities(array('<field_relate>_name_advanced'=>$_REQUEST['request_data'])),true);
}else{
$tmp=json_decode(html_entity_decode($_REQUEST['request_data']),true);
$parametrs_advanced='`<field_relate>_name`="'.$tmp['<field_relate>_name_advanced'].'"';// example part of SQL WHERE
}
$popupMeta = array (
...
'whereStatement'=> "$parametrs_advanced",
...
);
You should write correct parameter WHERE of SQL request.
Yes, the name is correct, $_REQUEST['<field_relate>_name_advanced'] returns the correct value only the first time, when the popup appears, then when I click the search button (with no value set), $_REQUEST['<field_relate>_name_advanced'] is empty
I don’t know if correct, anyway I modified the code like this:
if(!empty($_REQUEST['<field_relate>_name_advanced'])){
$parametrs_advanced='`<field_relate>_name`="'.$_REQUEST['<field_relate>_name_advanced'].'"'; // example part of SQL WHERE
$_REQUEST['request_data']=$_REQUEST['<field_relate>_name_advanced'];
}else{
$parametrs_advanced='<field_relate>_name="'.$_REQUEST['request_data'].'";// example part of SQL WHERE
}
and it works, now the problem is the query, it gives me an error because it rightly doesn’t recognize the <field_relate>_name field within the Users form, since it is related field of my custom form, how do I tell it to refer to that field which is not in the Users form?
@fab , hello bro, were you able to fix it? I was able to implement it but my problem is when you search the name on a popup view there will be no result even the names are existing.
<?php
if(!empty($_REQUEST['city'])){
$parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
$parameters_advanced='`dvt3_city_id_c`=""';// example part of SQL WHERE
}
But it will work if I set the parameters to $parameters_advanced = " ". Check sample code below:
<?php
if(!empty($_REQUEST['city'])){
$parameters_advanced='`dvt3_city_id_c`= "'.$_REQUEST['city'].'"'; // example part of SQL WHERE
}else{
$parameters_advanced='';// example part of SQL WHERE
}
The only disadvantage on this code is even there is no value on the province which is my first field, all the data on city popupdefs will display. The pre-filtered customization will be pointless if it will display all data of the city.