Registering a user with a relationship field
Support › MB User Profile › Registering a user with a relationship field
- This topic has 7 replies, 2 voices, and was last updated 2 years, 1 month ago by
Yasmine.
-
AuthorPosts
-
March 14, 2023 at 8:53 PM #41013
Yasmine
ParticipantHi Peter,
I promise this is the last from me!
I have a frontend form to register a new user, in it I have added a relationship field to attach the user to a post (in my case, a university)
However, this form is creating a new meta box and not using the relationship field that I created. This is my code to add the relationship field to the user register form:
[ 'name' => __( 'University', 'your-text-domain' ), 'id' => 'university_user', 'type' => 'post', 'post_type' => ['university'], 'field_type' => 'select_advanced', 'field' => [ 'query_args' => [ 'orderby' => 'title', 'order' => 'ASC', ],],],
Can you see where I am going wrong?
Yasmine
March 14, 2023 at 8:54 PM #41014Yasmine
Participantuniversity_user is the name of the relationship ID
March 15, 2023 at 6:51 PM #41025Peter
ModeratorHello,
It's not possible to add the relationship ID as a field ID like that. If you want to display the relationship meta box on the frontend, please add this meta box ID to the frontend shortcode
university_user_relationships_from
oruniversity_user_relationships_to
For example:
[mb_frontend_form id="meta-box-id1,university_user_relationships_to"]
Please read more on this topic https://support.metabox.io/topic/mb-relationships-mb-frontend-submission/?swcfpc=1#post-16736
March 16, 2023 at 1:22 AM #41034Yasmine
ParticipantHi Peter,
Ok so that means I made it :
[mb_frontend_form id="mb_user_profile_register,university_user_relationships_to" label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]
But with this, all I get is a select already created user box. Whereas...
[mb_user_profile_register label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]
Rendered the correct form and with all my added fields, which I added via a php snippet. Only the relationship not working.
I removed the relationship field (that I shared in my last code) from the php snippet
And I also tried _relationship_from - but in that case, nothing rendered.
What am I now doing wrong?
Many thanks,
YasmineMarch 16, 2023 at 6:13 PM #41035Peter
ModeratorHello,
Can you please share some screenshots of the issue on your site and the relationship ID? Also, please note that:
mb_user_profile_register
is not a field group (meta box) ID to add to the frontend submission shortcode. It's the shortcode name of the user profile.
Did you create a field group with the IDmb_user_profile_register
?March 16, 2023 at 6:39 PM #41040Yasmine
ParticipantOh but I want to add the relationship field into the profile register. As it is a university, I want to attach the university via a relationship post when we register a new user..
So in the first message, the code I shared was to add to edit this:
function add_more_registration_fields($fields) { $first_fields = [ ... [
March 16, 2023 at 6:46 PM #41041Yasmine
ParticipantAnd when I add it in the correct way that you suggest:
'[mb_user_profile_register mb_frontend_form id="university_user_relationships_to" label_submit="Add new" confirmation="Your academic has been added" role="contributor" show_if_user_can="create_users" email_as_username='true' email_confirmation="false" password_strength="false" ]'
At the bottom, it does not link to selecting the university post. It just lets you select a different user - not university.
I am unable to use pastebin to share a screenshot.
March 16, 2023 at 6:48 PM #41042Yasmine
ParticipantOh I see - it needed to be 'from'. Sorry about that.
The only issue now is that is right at the bottom of the form in a position that does not make sense and does not have a title - so does not match how I formatted the rest of the form. How can I fix this?
Thank you.
-
AuthorPosts
- You must be logged in to reply to this topic.