Forum: F.A.Q

This forum is closed for new topics. However, you can still search for a solution in the old topics. For technical support and general questions related to GEO my WP plugin and its core add-ons please use the support forum.

[Waiting for user confirmation]How to Set a Default Value in Search Form

Home Forums F.A.Q How to Set a Default Value in Search Form

This topic contains 19 replies, has 5 voices, and was last updated by  mgparisicpugmail-com 7 months, 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #39170

    squints
    Participant

    My XProfile fields include a privacy field which is a yes/no dropdown, those who select ‘no’ will not be indexed in the search results. I need to include only the ‘yes’ value of this field in my search form since users aren’t supposed to be able to search for the ‘no’ value.

    How can I include this field in my “find members” search form as a hidden field with the default value set to ‘yes’?

    Is a paid add-on required just to hide a field? Or is there a standard solution?

    Thanks.

    #39627

    squints
    Participant

    Bump

    #39722

    Eyal Fitoussi
    Keymaster

    Hello Squints,
    No add-on is required for this functionality and basically this is something that can be done with a “simple” custom script. However, for some reason this script did work when I tested it ( as another user requsted the same thing you did ). I am looking into it and once I have a solution I will share it with you.

    #39822

    squints
    Participant

    Thanks Eyal,

    Please provide me with the solution ASAP!

    #40651

    squints
    Participant

    Any update on providing the solution for this Eyal?

    #40696

    Eyal Fitoussi
    Keymaster

    I am sorry but as mentioend in your other topic I will be able to look into the code and solution only once I am back to the country and on my computer.

    However, it seems like the other users who was looking for the same thing found a solution. Take a look at this topic which hopefully will help you solve it.

    #41049

    squints
    Participant

    Sorry but simply setting the other options as hidden via CSS isn’t going to solve the issue of needing to set a default value within a search form.  Thanks for the follow up and for pointing me to the other thread, I really hope when you return we can find a solution.

     

    Thanks.

    #42337

    Eyal Fitoussi
    Keymaster

    You will need to write a custom function that will get the user ID of the users who have the xprofile set to yes.

    You can get the user IDs using the example on BP has members ( scroll down ).

    This is the code I am referring to:

    You only need to get the array of the ID’s and pass it to the “include” argument of bp_has_members using the filter provided by GEO my WP:

    That should be a start point. I hope that help.

    #42451

    squints
    Participant

    This seems like a very heavy and overly complicated method of what is a pretty simple problem. All that I need to do is set one of the select options as the default value and then hide the select box (which I can do with CSS) so that the same value is passed every time someone submits a search. I should not need to modify the entire query just to select a default value within a dropdown that only has 2 values to start with…

    #42464

    squints
    Participant

    It seems like I need to use the gmw_default_form_values filter but the documentation has no examples on how to use the filter to set default values and it doesn’t appear that there is a includes/geo-my-wp-form-init-class.php file.

    #42469

    Eyal Fitoussi
    Keymaster

    The gmw_default_form_values filter won’t be useful in this case. This filter is to modify the form settings.

    At the moment I believe that you can use the script below ( in functions.php file ) to do that. The script uses JavaScript to change the value of a dropdown field. You will also need to hide it using CSS:

    You need to change the number 2 in #gmw-2-field-165 to the ID of the form that you modify and 165 to the field ID.

    I will need to improve an existing filter or to create a new one to make it possible to do what you asked for. Until then the above should do.

    Let me know if that helps.

    #42473

    squints
    Participant

    Okay that seems to do the trick for selecting a default value, thank you very much for following through with this and finding a solution.

    I am also wondering if there is a filter similar to the Post forms gmw_pt_dropdown_taxonomy_args for Friends forms? Do the dropdowns within the friends forms also use wp_dropdown_categories to display? I would like to remove the show_option_all value from the dropdown but I have had no luck using the wp_dropdown_categories format because it requires a taxonomy rather than an Xprofile field.

    #42494

    softdesigns
    Participant

    Regarding the code example you gave above –

    Can this code example be used to set the default value of a BuddyPress XProfile field in the GEO my WP search form?   If so, how can we find the id of an XProfile field?
    Thanks
    #42558

    Eyal Fitoussi
    Keymaster

    @squints,
    wp_dropdown_categories is a function provided by WordPress for taxonomy but there isn’t something similar for Xprofile fields. GEO my WP creates the xprofile fields dropdowns, checkboxes and so on using a custom scripts.
    There is not way at the moment to remove the “all” option ( unless you edit the core file ) but I am going to look into a solution. Probably add a filter or just improve the xprofile fields function in general.

    @SoftDesgins,

    Can this code example be used to set the default value of a BuddyPress XProfile field in the GEO my WP search form? If so, how can we find the id of an XProfile field?

    That is exactly what the script support to do.
    To find the field ID navigate to the admin dashboard -> Users -> Profile Fields. You should see the list of existing Xprofiel Fields. Click “Edit” for the xprofile Field that you’d like to modify and you should see the field ID in the URL ( ex &field_id=111 ).
    IN the script above remember to change the number 2 in #gmw-2-field-165 to the ID of the form that you modify and 165 to the field ID. Also change “Two” in “.val(‘two’);” to the value that you’d like to be the default.

    Let me know if you have any more questions.

    #42673

    Eyal Fitoussi
    Keymaster

    @squints and @SoftDesgins,
    I just release a new version of GEO my WP 2.6.2. The new version comes with new filters which allows you to set the default value for the xprofile fields in the search form. One of the filters also allows you to modify/remove to “All” option from the dropdown select boxes.

    Take a look at the new filters ‘gmw_fl_xprofile_form_dropdown_option_all’ and ‘gmw_fl_xprofile_form_default_value’.

    I hope that helps.

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic.