Update field before saving

Support General Update field before saving

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2026
    tandoigaitandoigai
    Participant

    Hi. Thank you for a great plugin.

    I'm using your plugin to create a post review system. I have a clonable group field like this:

    Criteria 1, Score 1
    Criteria 2, Score 2
    Criteria 3, Score 3

    ...

    I also create a hidden field called Total Score

    I wanna get Total Score = (Score 1 + Score 2 + Score 3 + ...) / n where n is the number of subfields in above group.

    Is there a way to alter value of Total Score before the post being saved?

    I'm a theme developer and I'/ good at filters & actions.

    Thank you so much.

    #2027
    tandoigaitandoigai
    Participant

    After digging into your code, I found the solution myself.

    Here's the solution for those who need:

    // there's a filter to alter value before post being saved
    add_filter ( 'rwmb_NAME_value', 'somefunction' );
    
    function somefunction() {
    
    // get data
    $get_data = isset( $_POST['SOMEKEY'] ) ? $_POST['SOMEKEY'] : null;
    
    // do something with your data, multiple by 100 for instance
    $modified_data = $get_data *100;
    
    // return the modified data
    return $modified_data;
    }

    Anyway thank you for crafting many hooks for ease of use.

    Cheers.

    #2029
    Anh TranAnh Tran
    Keymaster

    Glad that you find it! That's the correct way to do that. For more information about hooks, please look at this documentation.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Update field before saving’ is closed to new replies.