• Resolved abailey

    (@abailey)


    Using the tutorial at
    https://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/
    I’m trying to extend it to also edit existing instead of just submitting new.

    But I’m finding the get_sanitized_values(), which is used to clean $_POST variables, strips out empty fields. So there is no way to blank a field once it’s has data. A simple text field can be set to anything other than empty and be saved, but an empty text field is removed in the sanitized values.

    Same with checkboxes. Once any on of them is checked you can never save all of them as unchecked. Problem is definitely at the get_sanitized_values because you can watch the values disappear immediately after the call

          $this->log($_POST);
          $sanitized_values = $cmb->get_sanitized_values( $_POST );
          $this->log($sanitized_values);
    

    The empty value will be in $_POST and gone in $sanitized_values. Makes it impossible to erase a value.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not quite sure what the best course of action will be for this one, outside of not using that method and instead rolling your own solution for sanitization.

    I believe this all traces its way back to the save_field method inside of CMB2_Field class and it definitely has a handful of empty checks, which may not make it the best solution for this usecase.

    Throwing spaghetti at the wall here, perhaps separate parts out, use the sanitized values returned to update what needs to be, and then use the intended emptied values to unset the parts you need on your own. You should still be able to get those out of the $_POST global/

Viewing 1 replies (of 1 total)

The topic ‘get_sanitized_values() Doesn’t Pass Empty Values’ is closed to new replies.