Auto Relationship on form submission

Support MB Relationships Auto Relationship on form submission

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #31330
    Wojtek PiskorzWojtek Piskorz
    Participant

    Case study:

    CTA: Service
    CTA: Reviews

    Relationship 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 😉

    #31334
    Long NguyenLong Nguyen
    Moderator

    Hi 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.

    #31341
    Wojtek PiskorzWojtek Piskorz
    Participant

    OK 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 🙁

    #31365
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

    #36376
    ChrisChris
    Participant

    Hey 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.

    #36386
    Long NguyenLong Nguyen
    Moderator

    Hi 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

    #36479
    ChrisChris
    Participant

    Oh 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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.