Contact form
-
Dear all,
I would like to add a contact form on a profile tab. Ant idea ?
(I have bought the pp-contact form from plus plugins, but as they did not upgrade it to verion 2.0 , it does not work anymore on Ultimate member)
Thanks for you support !
FannyThe page I need help with: [log in to see the link]
-
Hi @fanny13,
I’m afraid, we don’t have a contact form option in the current version of the core plugin or out extensions.
You can add address and other contact fields to the profile form or create a new custom tab. Here is the code sample on how to add custom profile tab.
Regards.
Anyone who would like to have a contact form on the profile page and have it send to the owner of the profile (member):
I use Ninja Forms and set the ‘to’ address with merge tag {wp:admin_email}.
Then add this code to functions.php:
add_action('um_main_profile_fields', 'update_admin_email', 101); function update_admin_email() { $profile_id = um_profile_id(); $user_info = get_userdata($profile_id); $send_to_emous = $user_info->user_email; update_option('admin_email', $send_to_emous); // Optional to check: $email = get_option('admin_email'); // Optional to check: echo '<p style="color:red;">' . $email . '</p>'; }
It will update the site admin email address to the member address on this page, thus rendering the correct email address in the ‘to’ address.
=UPDATE=
In hindsight it was not a good idea to update admin_email each time a form was send, been working on this too long. Status is now ‘work around’ using the following code which updates a post meta field. Would love to hear feedback on this solution and possible better ones.
I have used the ACF plugin to add a custom field (key: custom_meta_key_emailz) to the profile page but of course native WP fields will work as well.
I use Ninja Forms and set the “to” address with merge tag {post_meta:custom_meta_key_emailz}
Code functions.php:
// Send email to profile owner add_action('um_main_profile_fields', 'update_admin_email', 101); function update_admin_email() { // Get member email $profile_id = um_profile_id(); $user_info = get_userdata($profile_id); $send_to_emous = $user_info->user_email; // Get custom field ACF $custom_emailz = get_post_meta( get_the_ID(), 'custom_meta_key_emailz', true ); // Update field ACF, alter in case of native fields update_field('custom_meta_key_emailz', $send_to_emous, 2411); // Optional to check: // echo '<p style="color:red;">$custom_emailz: ' . $custom_emailz . '</p>'; }
It will update the meta key “custom_meta_key_emailz” to the member address on this page, thus rendering the correct email address in the “to” address.
I haven’t tested this all out but I think the hooks available here would be more along the lines of getting a profile contact form using Ninja Forms.
I can’t write out all the code at the moment so I’ll explain a way to get to a solution using Ninja Forms.
- Add a custom tab to Ultimate Member Profile. See here
- Inside of the content of the tab, add a ninja form shortcode
- Using a Ninja Form hook, check to see if the submission is coming from a profile and if it is, then get the user email of that profile and change the recipient email to the profile email
So with the above mentioned, that’s one way to get a Contact Form embedded on a profile.
I am already supporting Contact Form 7 in my plugin but I will be extending it to Gravity Form, Ninja Form and WP Form.
=UPDATE UPDATE=
All my above ideas have been the worst, they work but not as expected. The post meta key gets updated each time the page gets hit and therefor it is possible (and actually very probable with larger sites) that while a visitor is filling in the form, another will visit another profile page and change the recipient email address for all forms :))
@suiteplugins Thank you for your suggestions I will check it out!
This is driving me insane, I am using the Ninja Forms filter above to populate a hidden field which I have added to the recipient field, but although the below code renders the correct profile email on the page itself I can seem to use it in the filter: it either returns the logged in user email or nothing at all when not logged in..
function store_profile_id(){ global $ultimatemember; $profile_id = um_profile_id(); $user_info = um_fetch_user( $profile_id ); $send_to_emous = um_user('user_email'); echo $send_to_emous; }
Hi there, this is much appriciated!
My code is the following:
// Profile page contact form connect to profile id add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' ); function my_ninja_forms_submit_data( $form_data ) { $profile_id = um_profile_id(); $user_info = get_user_meta($profile_id, 'user_email', true); // IDs foreach( $form_data[ 'fields' ] as $key => $field ) { if( $key == '47'){ $form_data['fields'][$key]['value'] = $user_info; } }
// Form settings.
$form_settings = $form_data[ ‘settings’ ];
// Extra data included with the submission.
$extra_data = $form_data[ ‘extra’ ];return $form_data;
}And it results in being able to send the contact form submission to myself if visiting my own profile logged in, all else fails although the code to retrieve the user id etc works on the page.
I have a feeling that this has something to do with the URL /admin/wp-admin.php from where the profile page is actually rendered, but I’m not sure and not capable to do something with this.
I have created a hidden field placed in the ‘to’ field of the form which I’m using the ID (47) to target the filter to. Unfortunately the original code on NF (using key) did nothing for me.
Thanks for any help!
- The topic ‘Contact form’ is closed to new replies.