multiple custom_member_field params
Posted: 26 April 2008 01:30 PM   [ Ignore ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

hi together,

i´ve to realise a member-search checking multiple arguments from custom_member_fields. neither keywords in search-tag nor the custom_member_field parameter in user:users seem to offer a handy solution for this. wouldn`t it be nice to have a custom_member_field parameter that handles more than one argument, like this: custom_member_field="firstname|mike,lastname|smith,gender|male"

or is there perhaps another solution i´ve never dreamed of?
thx
martin

Profile
 
 
Posted: 26 April 2008 01:46 PM   [ Ignore ]   [ # 1 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

in mod.user.php line 487+ happens following:

/** ----------------------------------------
  /** Filter by custom field
  /** ----------------------------------------*/
  
  if ( $custom_member_field = $TMPL->fetch_param('custom_member_field') )
  
{
   $this
->_mfields();
   
   
$custom_field = explode( "|", $custom_member_field );
   
   if ( isset(
$custom_field[0] ) AND isset( $custom_field[1] ) AND isset( $this->mfields[ $custom_field[0] ] ) )
   
{
    
if ( $filter_method == 'exact' )
    
{
     $sql
.= " AND md.m_field_id_".$this->mfields[ $custom_field[0] ]['id']." = '".$custom_field[1]."'";
    
}
    
else
    
{
     $sql
.= " AND md.m_field_id_".$this->mfields[ $custom_field[0] ]['id']." LIKE '%".$custom_field[1]."%'";
    
}
   }
  }

when i use some new parameters in user:users tag like custom_member_field2, custom_member_field3, ...
it should be possible to simply duplicate the above code and modify like ...

if ( $custom_member_field = $TMPL->fetch_param('custom_member_field2') )
  
{
...

could this work?

Profile
 
 
Posted: 26 April 2008 01:59 PM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

works fine this way:

/** ----------------------------------------
  /** Filter by custom field
  /** ----------------------------------------*/
  
  if ( $custom_member_field2 = $TMPL->fetch_param('custom_member_field2') )
  
{
   $this
->_mfields();
   
   
$custom_field2 = explode( "|", $custom_member_field2 );
   
   if ( isset(
$custom_field2[0] ) AND isset( $custom_field2[1] ) AND isset( $this->mfields[ $custom_field2[0] ] ) )
   
{
    
if ( $filter_method == 'exact' )
    
{
     $sql
.= " AND md.m_field_id_".$this->mfields[ $custom_field2[0] ]['id']." = '".$custom_field2[1]."'";
    
}
    
else
    
{
     $sql
.= " AND md.m_field_id_".$this->mfields[ $custom_field2[0] ]['id']." LIKE '%".$custom_field2[1]."%'";
    
}
   }
  }

and so on.

Profile
 
 
Posted: 28 April 2008 06:14 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3350
Joined  2006-10-18

Neat… thanks! smile

I’ll have a Mitchell take a look at this smile

 Signature 
Profile
 
 
Posted: 08 May 2008 01:50 PM   [ Ignore ]   [ # 4 ]
Jr. Member
RankRank
Total Posts:  37
Joined  2007-09-29

martin_f If I understood you right, you meen search form like this???
Here I have a custom field “Who is he” and I use

<select name="m_field_id_1" class="select">
<
option value="Good boy">Good boy</option>
<
option value="Bad boy" selected="selected">Bad boy</option>
<
option value="What?">What?</option>
</
select>

How to make work this search???????????

Image Attachments
11.jpg
Profile
 
 
Posted: 08 May 2008 02:08 PM   [ Ignore ]   [ # 5 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

hi qrat. i´m not sure if i understand right, but i think the tag should look something like this.

{select_fieldname}
  
<option value="{value}">{value}</option>
  
{/select_fieldname}

Profile
 
 
Posted: 09 May 2008 12:08 AM   [ Ignore ]   [ # 6 ]
Jr. Member
RankRank
Total Posts:  37
Joined  2007-09-29

I just want to search not only category.
In custom fields too.

For example, my users is a companies. Each of them assigned to their category (engineering, marketing, web-developing ect...)
Also they have some custom fields with drop-down menu (Area: Alabama, New York, Washington ect… Number of employers: 5, 6-10, 11-50 ect...)

So, when I use {exp:user:search
I can use drop-down only in categories, but not in my custom field Area and Number of employers.

<select name="category[]">
{categories}
{category_selected}selected
="selected"{/category_selected}
{category_body}
<option value="{category_id}" {selected}>{category_name}</option>{/category_body}
{
/categories}
</select>

Profile
 
 
Posted: 09 May 2008 12:21 AM   [ Ignore ]   [ # 7 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

for the user:search-tag, you can only give a keyword and limit the search-range (for fields) via the skip_field paramater, i think. it should be possible to build a user:search form for every of your fields and use the skip_field parameter to limit each search on a specific field (exclude all others in search).

Profile
 
 
Posted: 09 May 2008 12:30 AM   [ Ignore ]   [ # 8 ]
Jr. Member
RankRank
Total Posts:  37
Joined  2007-09-29

Yes you right, I can use a keyword, but more comfortable will use drop-down.
I didn’t understand you correct, what do you mean “a user:search form for every of your fields” ?

Profile
 
 
Posted: 09 May 2008 01:26 AM   [ Ignore ]   [ # 9 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

i haven`t done anything with categories and the user module, but what i mean is, you can offer a (keyword)-searchform as a selectfield for
any custom- or standard_member_fields data.

{exp:user:search form_name="form1" return="{path=tplg/tpl}" group_id="5" form_id="fid"
skip_field="fieldname1|fieldname2|fieldname3"}
<label for="keywords"></label>  
<
select id="keywords" name="keywords">
<
option value="" selected="selected">choose:</option>
<
option value="New York" >New York</option>
</
select>
<
p><input type="submit" value="submit" /></p>
{/exp:user:search}

... finds the value in every field that isn`t named fieldname1, -2 or fieldname3.

{exp:user:search form_name="form1" return="{path=tplg/tpl}" group_id="5" form_id="fid"
skip_field="fieldname1|fieldname2|fieldname4"}
<label for="keywords"></label>  
<select id="keywords" name="keywords">
<option value="" selected="selected">choose:</option>
<option value="New York" >New York</option>
</select>
<p><input type="submit" value="submit" /></p>
{/exp:user:search}

... finds the value in every field that isn
`t named fieldname1, -2 or fieldname4.
so New York (as value in fieldname3) won`t get found in the first example, but
true in the 2nd example.

the problem is, you can`t combine these 2 forms and the select-form values have to be hardcoded.
for what you want, when i`m right, you have to use the user:users tag. in this tag you can get the custom_member_field values like so ..

{select_fieldname}  <option value="{value}">{value}</option>  {/select_fieldname}

... and, if you use this in an embed-template as resultpage, with php-parsing on input, grab the
$_POST array and build a function to generate a custom user:users param like this:

<?php if(isset($_POST['formfieldname']) and $_POST['formfieldname'] != "") {
$custom_field_params
.= " custom_member_field_fieldname=\"".$_POST['formfieldname']."\""; } ?>
  {exp
:user:users group_id="5" limit="18" paginate="bottom" orderby="join_date" sort="desc" filter_method="any"
<?php echo $custom_field_params; ?>}

  
... where $custom_field_params is something like: custom_member_field="searchsex|Frau"
custom_member_field_fieldname="18" ....

to recieve this additional parameters you have to edit system/modules/user/mod.user.php like described on top of the thread. for this
example here, we have to add some lines like this:

/** ----------------------------------------
  /** Filter by custom field fieldname
  /** ----------------------------------------*/
  /**/
  if ( $custom_member_field = $TMPL->fetch_param('custom_member_field_fieldname') )
  
{
   $custom_field
= $custom_member_field;   
   
   if ( isset(
$custom_field ) )
   
{
  $plus
= 0;
  
$plus = $custom_field;
  
$plus = $plus+20;
  
$sql .= " AND md.m_field_id_27 BETWEEN '".$custom_field."' AND '".$plus."'";

   
}
  }

this seems to be working solution. code above is not really tested, just a quick snippet.

Profile
 
 
Posted: 09 May 2008 02:35 AM   [ Ignore ]   [ # 10 ]
Jr. Member
RankRank
Total Posts:  37
Joined  2007-09-29

I think I made this search form works as I wanted.
Here is my code

{exp:user:search form_name="your_form_name" return="{path=panel/searchu}"}

<fieldset>

<
legend>Search</legend>
Keywords<br>
<
input type="text" class="input" maxlength="100" size="40" name="keywords" id="keywords" />

<
br>Area<br>
<
select name="area" class="select">
<
option value="Alabama">Alabama</option>
<
option value="New York" selected="selected">New York</option>
<
option value="Washington">Washington</option>
</
select>
<
br>Number of employer<br>
<
select name="what" class="select">
<
option value="5">5</option>
<
option value="6-10">6-10</option>
<
option value="11-50" selected="selected">11-50</option>
</
select>
<
br>

<
input type='submit' value='Search' class='submit' />

</
fieldset>
{/exp:user:search}

As you can see, I parced my custom fields. I checked, It works as I need.

But. I would like it work automatically, I mean I need some query, which grab my fields (New York, Washington)

Profile
 
 
Posted: 09 May 2008 03:45 AM   [ Ignore ]   [ # 11 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

before your code something like this:

<?php
  $value_array_area
();
  
$value_array_what();
?>
{exp
:user:users group_id="1" limit="1" orderby="join_date" sort="desc"}
{select_area}
<?php $value_array_area[]
= "{value}"; ?>
{
/select_area}
{select_what}
<?php $value_array_what[]
= "{value}"; ?>
{
/select_what}
{
/exp:user:users}

... and then your code with select-options like this:

...
<
select name="what" class="select">
<?php
foreach($value_array_what as $option) {
  
echo "<option value=\"$option\">$option</option>";
}
?>
</select>
...

Profile
 
 
Posted: 09 May 2008 03:54 AM   [ Ignore ]   [ # 12 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23
Qrat - 09 May 2008 02:35 AM

I think I made this search form works as I wanted.
Here is my code

{exp:user:search form_name="your_form_name" return="{path=panel/searchu}"}

<fieldset>

<
legend>Search</legend>
Keywords<br>
<
input type="text" class="input" maxlength="100" size="40" name="keywords" id="keywords" />

<
br>Area<br>
<
select name="area" class="select">
<
option value="Alabama">Alabama</option>
<
option value="New York" selected="selected">New York</option>
<
option value="Washington">Washington</option>
</
select>
<
br>Number of employer<br>
<
select name="what" class="select">
<
option value="5">5</option>
<
option value="6-10">6-10</option>
<
option value="11-50" selected="selected">11-50</option>
</
select>
<
br>

<
input type='submit' value='Search' class='submit' />

</
fieldset>
{/exp:user:search}


As you can see, I parced my custom fields. I checked, It works as I need.

But. I would like it work automatically, I mean I need some query, which grab my fields (New York, Washington)

question to the module makers:
is it possible to hand over a custom_member_field-name/value in the search-tag as qrat describes above? it`s not documented and as i remain, it hadn`t worked in my case.

Profile
 
 
Posted: 09 May 2008 06:40 AM   [ Ignore ]   [ # 13 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3350
Joined  2006-10-18
martin_f - 09 May 2008 03:54 AM

question to the module makers:
is it possible to hand over a custom_member_field-name/value in the search-tag as qrat describes above? it`s not documented and as i remain, it hadn`t worked in my case.

martin_f,

This is definitely possible with User Search smile
| apologize as the documentation was very obscure about this feature, and if you noticed it, it was probably confusing LOL
I’ve updated the Docs: User Search: Custom Member Fields

I will not though, this feature is intended to be “complimentary” to the Keywords search, much like Qrat has it smile
Although, it does work if you JUST use custom fields without the “keywords” form field.

It’s intended purpose is to further filter your results. So if you’re testing this and it isn’t working, it could be that you do not have any users that match ALL criteria smile

 Signature 
Profile
 
 
Posted: 09 May 2008 07:08 AM   [ Ignore ]   [ # 14 ]
Newbie
Rank
Total Posts:  17
Joined  2006-09-23

thanks pie man, good to know.

Profile