Custom Fields
Re-Envisioned
Support MB Frontend Submission What is the best way to process submitted field data before save it?

  • Creator
    Topic
  • #33143
    Resolved Marco T Nascimento
    Participant

    What is the best way to process frontend submitted field data before save it? Is there a filter that has access to all submitted fields at the same time? I need to process multiple fields and save the result in one of them.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #33150
    Long Nguyen
    Moderator

    Hi Marco,

    There is a filter rwmb_frontend_insert_post_data that is used to modify the submitted post data before saving it to the database. Read more on the documentation https://docs.metabox.io/extensions/mb-frontend-submission/#post-data-filters

    #33166
    Marco T Nascimento
    Participant

    Thank you. I've succeeded saving standard post fields with the following code. However, it doesn't work with custom meta fields. Could you please give me some guidance on how to do that? Tks.

    ps: I'm using MB Frontend Submission and MB Custom Table extensions.

    Here is the sample code:

    add_filter( 'rwmb_frontend_update_post_data', 'zy_before_save_post', 10, 2 );
    add_filter( 'rwmb_frontend_insert_post_data', 'zy_before_save_post', 10, 2 );
    function zy_before_save_post( $data, $config ) {
    
    $data['post_title'] = "some title"; // okay
    $data['post_content'] = "some content"; // okay
    $data['my_field_id'] = "some data"; // do not work
    $data['meta_input']['my_field_id'] = "some data"; // do not work
    return $data;
    
    }
    #33179
    Long Nguyen
    Moderator

    Hi Marco,

    It looks like those filters do not work with custom fields, you can try to use the action hook rwmb_frontend_after_save_post to update the field value after saving the post. For example

    add_action( 'rwmb_frontend_after_save_post', 'zy_after_save_post' );
    function zy_after_save_post( $object ) {
    $wysiwyg = $_POST['wysiwyg'];
    
    $wysiwyg = '123456';
    rwmb_set_meta( $object->post_id, 'wysiwyg', $wysiwyg );
    }

    Access the field value via the global variable $_POST. Refer to this topic https://metabox.io/support/topic/use-rwmb_frontend_after_save_post/

    #33197
    Marco Nascimento
    Participant

    Thank you

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