Auto Relationship on form submission
Support › MB Relationships › Auto Relationship on form submission
- This topic has 6 replies, 3 voices, and was last updated 2 years, 10 months ago by
Chris.
-
AuthorPosts
-
October 15, 2021 at 6:51 AM #31330
Wojtek Piskorz
ParticipantCase study:
CTA: Service
CTA: ReviewsRelationship between those 2.
On single service template I have a form with: 1-5 rating, name, text content that creates a review post.
Is it possible to setup the form to automatically create a relationship between review post that was created with a form submission and the single service that the form was submitted on this?
And cherry on top: is it possible to use with fluent form integration 🙂 - I use FF integration for metabox submissions at the moment and I love it 😉
October 15, 2021 at 11:01 AM #31334Long Nguyen
ModeratorHi Wojtek,
Yes, it is possible to set the automatic relationship between the post submitted with the current page. Use this code to create a connection after submitting the form.
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) { MB_Relationships_API::add( get_queried_object_id(), $post_id, 'your-relationship-ID', $order_from = 1, $order_to = 1 ); }, 10, 2 );
Refer to this topic https://support.metabox.io/topic/prepopulate-relationship-field-with-current-post-id/
Both Fluent Forms and MB Frontend Submission support submitting a post from frontend so I think you should use one.
October 16, 2021 at 5:00 AM #31341Wojtek Piskorz
ParticipantOK so here:
https://fluentforms.com/docs/fluenform_before_submission_confirmation/I found an action that FF folks recommend to use if I want to execute any custom functionality.
I'm trying to adjust the code you kindly provided and I just don't know how it's suppose to looks like.I also tried to exactly follow your loom tutorial (with use of MB forms) and it didnt work as well. Only difference I made was I used build-in relationship builder instead of coding it with codeblock.
Sorry for being noob 🙁
October 18, 2021 at 9:34 AM #31365Long Nguyen
ModeratorHi,
Follow the FF documentation, you can try to use this code
add_action('fluentform_before_submission_confirmation', 'your_custom_confirmation_function', 20, 3); function your_custom_confirmation_function( $entryId, $formData, $form ) { // Do your stuff here MB_Relationships_API::add( get_queried_object_id(), $entryId, 'your-relationship-ID', $order_from = 1, $order_to = 1 ); }
to add the relationship between the post submitted via the form and the current page that shows the form.
June 8, 2022 at 9:55 PM #36376Chris
ParticipantHey Long,
I sifted through all the tickets and found this one, which is what I am trying to do. I just can't seem to get it to work.
Could you help me make sure I have the relationship setup correctly?
Tickets (CPT)
Replies (CPT)FluentForm shown on Ticket page -> Create a Reply Post.
MB Relationship: From Ticket -> To Reply.
Nothing populates using the code above. I feel that I am so close.
Happy to grant admin access if that helps.
June 9, 2022 at 12:47 PM #36386Long Nguyen
ModeratorHi Chris,
Please make sure that the relationship between Ticket and Reply is registered. Refer to this documentation https://docs.metabox.io/extensions/mb-relationships/#using-code
June 14, 2022 at 7:52 PM #36479Chris
ParticipantOh yes, that is done in the plugin settings under relationships as I mentioned:
MB Relationship: From Ticket -> To Reply
I tried to flip it as well but still not populating.
I will try the code route and then reach out to FluentForms.
If you have any next steps beyond ensuring the relationship is set, let me know.
Thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.