Front-end submission to unrelated db table?

Support MB Frontend Submission Front-end submission to unrelated db table?Resolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23102
    Martin AsshetonMartin Assheton
    Participant

    Hi, Is it possible to use front-end submission to update an unrelated db table please?
    Many thanks, M

    #23103
    Long NguyenLong Nguyen
    Moderator

    Hi Martin,

    Yes, you can use action hooks rwmb_frontend_before_save_post or rwmb_frontend_after_save_post to trigger a function to update some value to the database.

    It accepts 1 parameter $object: the instance of the \MBFS\Post class, which handles the submission so you can access 4 properties:

    $post_type $post_id $fields $config

    See more in the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#post-actions.

    #23104
    Martin AsshetonMartin Assheton
    Participant

    Hi Long,

    Thanks for the prompt reply 🙂

    If I wanted to use Meta Box and MB Frontend submission to quickly create front-end forms to collect data which is not post-related, here is one way I can utilise the ease of MB Frontend Submission to populate my custom table: On frontend submission of a field-group a new (CPT) post is created, add my submitted data to a custom table and then delete the newly created post using rwmb_frontend_after_save_post whilst keeping my Custom Table table data.

    I cannot do this through MB custom tables as all db entry rows need to be associated with a post/user/taxonomy? Is that right?

    Would this be an advisable execution or would you suggest another route?

    The aim is to use the speed and flexibility coding with Meta Box and MB Frontend Submission, whilst adding data to custom tables which have no connection to posts, taxonomies or users.

    Sorry for all the questions and if you have any advise in how to execute this via Meta-box I'd be very interested - Currently I have it all hard-coded and its a slow process to update/edit!

    Ps. IF I Ajax call a post into a modal window (Bootstrap) using either admin-ajax or admin-post MB Frontend Submission will not execute - Is there are solution for this or is it out of scope for Meta Box please?

    #23105
    Long NguyenLong Nguyen
    Moderator

    Hi Martin,

    Please follow this documentation https://docs.metabox.io/extensions/mb-custom-table/#query-posts-with-wp_query.

    global $wpdb;
    $ids = $wpdb->get_col( "SELECT ID FROM your_table WHERE field1 = 'value1' OR field2 = 'value2'" );

    The custom table helps you track the data by post ID for each row and create the WordPress query to get full information base on post ID.

    You can still keep the data in the custom table and query to the database to get the data even delete the post.

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