News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Custom field - select box not searchble

Started by radu81, September 29, 2014, 07:24:05 AM

Previous topic - Next topic

radu81

hello,

I've just added a custom field to my registration and I noticed that text fields are searchble, but select box (single option) are not searchble. Is that a bug or there is a reason that this kind of fields are not searchble?

Why do I need such a filed? to add to my users the "region" field. there are about 20 in Italy

thank you in advance
sorry for my bad english

Illori

sounds like there really is nothing to search as the user is not inputting anything to search on.

Kindred

Exactly...  The contents of the select are not stored...   Only the index. (E.g. The number of the option) so there is nothing that can be searched.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

Looking at the code for the members search, in the custom fields part:
AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea})',
So it's clear that only custom profile fields of "text" type are "searchable"
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

Quote from: Kindred on September 29, 2014, 06:14:43 PM
Exactly...  The contents of the select are not stored...   Only the index. (E.g. The number of the option) so there is nothing that can be searched.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Quote from: Kindred on September 29, 2014, 06:14:43 PM
Exactly...  The contents of the select are not stored...   Only the index. (E.g. The number of the option) so there is nothing that can be searched.

The actual value selected is what is stored, or it was last time I looked.

EDIT: Checked, yes, the actual value in smf_themes for a selectbox is the actual content selected, not the index.

Kindred

Really? Hmmm... I could swear that only the numbers were stored last time I checked...

Although, the code margarett posted clearly indicates that only text type fields are searched...  I was under the impression that was because the others could not be searched. Hmmmmmmmm mm....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Deliberate design choice, but I have no idea why that would be the case.

Kindred

Hmmm...   If so, this is definitely something to be reported as a desired change for fix after the initial beta of 2.1
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Same deal with radio buttons too, IIRC (didn't check)

Fairly sure there's some technical reason for it but nothing comes to mind.

radu81

so is this a bug? is there a way to make a select box searchable in my user list?

My users asked this feature because they usually make some small meetings and they want to contact the people near them
sorry for my bad english

Kindred

no it is not a bug. This is completely by design. However until I have the devs look closer at the code I cannot imagine why it was designed that way...    however, again... it will not be changed in 2.0.x.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

radu81

sorry for my bad english

Kindred

Well, 2.0.x is only receiving security updates and a few bug fuxes. Since this is neither  a bug nor a security issue..........

I also can not promise it would be changed  in 2.1, since there  may be an actual reason it was not done, originally.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

radu81

Thanks for answering.

I'll try to "solve" this in a different way, by displaying custom fields on userlist. I found this mod http://custom.simplemachines.org/mods/index.php?mod=1520
sorry for my bad english

margarett

#15
There has to be something more "deep" for this desing choice. It's easy to get the select box to be searchable. As Arantor says, it's the selected value that gets stored in the custom field value.
But when I select it to be searched I get a "Hacking attempt" and I have no idea why :P

edit: in error log I get this:


http://localhost/smf2/index.php?action=mlist;sa=search
Hacking attempt...

SELECT COUNT(*)
FROM smf_members AS mem
LEFT JOIN smf_membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = 0 THEN mem.id_post_group ELSE mem.id_group END)LEFT JOIN smf_themes AS tcust_select ON (tcust_select.variable = 'cust_select' AND tcust_select.id_theme = 1 AND tcust_select.id_member = mem.id_member)
WHERE (member_name LIKE '%asdasd%' OR real_name LIKE '%asdasd%' OR email_address LIKE '%asdasd%' OR IFNULL(tcust_select.value, '') LIKE '%asdasd%')
AND mem.is_activated = 1
Function: MLSearch
Apply Filter: Only show the errors from this file
File: C:/xampp/htdocs/smf2/Sources/Memberlist.php
Line: 541
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Hacking attempt on a query means it doesn't like bare ' in the query.

margarett

No idea where that comes from :P I didn't put it there :P
I just added this part
OR IFNULL(tcust_select.value, '') LIKE '%asdasd%'
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Yes, you have a bare ' in the query :P

You need to inject the empty string and the other string by way of {string:...} parameters.

margarett

That's how the query is built itself, it wasn't me :P

I did this:
// Can they search custom fields?
$request = $smcFunc['db_query']('', '
(...)
AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea})',
array(
(...)
'field_type_text' => 'text',
'field_type_textarea' => 'textarea',
)
);

Changed to:
// Can they search custom fields?
$request = $smcFunc['db_query']('', '
SELECT col_name, field_name, field_desc
(...)
AND (field_type = {string:field_type_text} OR field_type = {string:field_type_textarea} OR field_type = {string:field_type_select})',
array(
(...)
'field_type_text' => 'text',
'field_type_textarea' => 'textarea',
'field_type_select' => 'select',
)
);

The query itself is built some lines below

// Any custom fields to search for - these being tricky?
foreach ($_POST['fields'] as $field)
{
$curField = substr($field, 5);
if (substr($field, 0, 5) == 'cust_' && isset($context['custom_search_fields'][$curField]))
{
$customJoin[] = 'LEFT JOIN {db_prefix}themes AS t' . $curField . ' ON (t' . $curField . '.variable = {string:t' . $curField . '} AND t' . $curField . '.id_theme = 1 AND t' . $curField . '.id_member = mem.id_member)';
$query_parameters['t' . $curField] = $curField;
$fields += array($customCount++ => 'IFNULL(t' . $curField . '.value, {string:blank_string})');
$search_fields[] = $field;
}
}

$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}members AS mem
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:regular_id_group} THEN mem.id_post_group ELSE mem.id_group END)' .
(empty($customJoin) ? '' : implode('
', $customJoin)) . '
WHERE (' . implode( ' ' . $query . ' OR ', $fields) . ' ' . $query . $condition . ')
AND mem.is_activated = {int:is_activated}',
$query_parameters
);

And I didn't really touched this part, so...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Advertisement: