0

I want to create a form on frontend that has a Chosen fieldtype that lets you search all the members on your site and filters it as you type. Is this possible with freeform pro?

I'm using template (custom markup and just putting fields where i need them), so I'm not using Composer.

As an alternative solution I'm thinking of creating a hidden text field, and in my markup just have a typical VM Chosen fieldtype that searches members as you type... and then use jQuery to take that name and put it as the user for Freeform's text field. Not sure if that would work but want to see if there's any other way first. I have over 2,000 members that someone needs to choose from in this form so Chosen is best option I think.

1 Answer 1

1

I think you're on the right path, gather a list of user/names then call that list inside a custom freeform:form would be the way to go. A module that deals with member data could likely be beneficial but for now, we'll just use the query tag and Stashes set:list to capture the list and store it for a week:

{exp:stash:set_list 
  name="members"
  save="yes" 
  replace="no"
  refresh="10080" {!-- 1 week --}
  scope="site"
  trim="yes"}
    //The raw query
    {exp:query sql="SELECT * FROM exp_members GROUP BY group_id"}tags 
      {stash:name}{screen_name}{/stash:name}
      {stash:id}{member_id}{/stash:id}
    {/exp:query}
{/exp:stash:set_list}

Then further down the template, put your form inside stash:parse tags to make sure it runs after stash has already captured the contents previous.

{exp:stash:parse}
  {exp:freeform:form}
  // Fields for form
  <select name="members" id="members">
  {exp:stash:get_list name="members" scope="site"}
    <option value="{id}>{name}</option>
  {/exp:stash:get_list}
  </select>
  {exp:freeform:form}
{/exp:stash:parse}

Then use the raw jQuery Chosen script and set up as described in their docs.

This is all pretty crude but we're gathering a list of users and 'stashing' the results for a long period. Once the list is stashed we can call it anywhere on the site but also on the page and have that list spit out inside a select that you can wire up to Chosen (jQuery).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.