PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Contact form for a Buddypress user directory

  1. I am new to GF, and purchased a dev license to use on a different site, but I would like to implement a contact form on a buddypress site I maintain with about 300 users in the database.

    Here's my use case: I would like to have the contact form show up on member's profiles, and allow people to contact site members through the form without exposing the member's email address. The members' email addresses are part of the wp_users table.

    So, where would I start looking to hook into GF and direct the output of the form? Does anyone have experience doing this sort of thing?

    Posted 13 years ago on Thursday August 11, 2011 | Permalink
  2. So, when viewing another member's profile, there will be a form present that anyone can use to submit a message to that member? Sort of like how the PMs work in BuddyPress now, but in a nicer looking manner with Gravity Forms? I think all the communication will be logged as well. Not sure if that's desirable or not.

    If that's what you're looking to do, we can help with the customization. Please post more details of how you envision it will work.

    Posted 13 years ago on Thursday August 11, 2011 | Permalink
  3. Hey Chris, You have described it exactly -- anyone, like anyone on earth, not just logged in users, or I'd just use the PM feature in BuddyPress. Don't think that the logging is necessary. I was looking to dig into developing with GF more myself, rather than outsource the work. I am looking for pointers on where to start looking in the docs to get GF talking with other things, and tips on how to approach the GF environment. Like, would it be better to dynamically insert a hidden field with the user's ID, and then port that to the forms output email onsubmit, or is there a better/slicker/more elegant way of doing that with GF?

    Posted 13 years ago on Thursday August 11, 2011 | Permalink
  4. The logging is just a byproduct of using a Gravity Form. You're going to have a record of every form submission. You will have to figure out what to do with those submissions.

    Sounds like you will have one form and will populate the "To:" email with the email address from that member's BuddyPress profile. I think this will work for you. Add this to your functions.php:

    function populate_bp_member_email() {
            global $bp;
            return $bp->displayed_user->userdata->user_email;
    }
    add_action('gform_field_value_email', 'populate_bp_member_email');

    I'm pretty sure that function will work to get the email of the displayed user. I don't have BuddyPress installed, so you might have to modify that code to make it work. Try it like that and see.

    This hook is the key: gform_field_value_$parameter. You can read more about it here: http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    Insert a hidden field into your form, and on the advanced tab, check the box to "Allow field to be populated dynamically". After that, you will have a text box for "Parameter Name:". In that box, use the same word you used in the hook. In my case it was email (gform_field_value_email), so I entered email here.

    http://min.us/meoFecw

    That word is important and can be almost anything. The key is to make the parameter name for the hidden field and in the filter the same. For me, it was email, same in both places.

    Now you have a function to get the email from the BuddyPress profile, and are inserting that email into a hidden field in the form. Now, you need to use that email in the notification email. I used this in my "To:" email {Member Email:1} (Member Email is the title of field one in my form.)

    Now use the function call to embed the form in whichever BuddyPress templates you want. You can read about how to do that here:

    http://www.gravityhelp.com/documentation/page/Embedding_A_Form

    Be sure when using the function call to insert the form that you also enqueue the scripts and stylesheets. It's all at the bottom of that page.

    Please post again if you need more help. Thanks.

    Posted 13 years ago on Friday August 12, 2011 | Permalink
  5. Hi Chris and thanks for your very comprehensive answer! I'll be trying all this out ASAP! Thanks again.

    Posted 13 years ago on Monday August 15, 2011 | Permalink
  6. I'm trying to solve a similar problem right now. I've gone through this solution, but I'm running into two problems (and these may be rookie issues because I have yet to do any really advanced GF coding).

    1) When you use this filter, the email address winds up showing right in the HTML of the form - just in a hidden field, so you haven't really done much obscuring to secure the user from spam.

    2) I can't seem to use a hidden field as an email-to address on notifications.

    What am I missing?

    Posted 13 years ago on Monday August 15, 2011 | Permalink
  7. Ok, now I'm seeing that the {Email:1} syntax *does* work in the To Field, but we're still not actually hiding any information.

    Next step was to move to the notification hooks instead of the form rendering hooks:
    http://www.pastie.org/2376575

    I'm actually not using BP, but just a custom field for the post, but you'll get the gist of using the gform_notification_email filter instead.

    Note also, that this method doesn't require anything special on the form. Just the form id. There's some simple documentation here: http://www.gravityhelp.com/documentation/page/Gform_notification_email

    Posted 13 years ago on Monday August 15, 2011 | Permalink
  8. Thanks for the code update.

    Posted 13 years ago on Monday August 15, 2011 | Permalink

This topic has been resolved and has been closed to new replies.