Custom Field and Post Edit Screen Field

Support MB Frontend Submission Custom Field and Post Edit Screen FieldResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32293
    Nicholas CoxNicholas Cox
    Participant

    Hi

    Ihave created the following custom field, it uses 'Flatpickr' JS library. The form field works ok and inputs the date value and saves it to the database successfully.

    My issue is that on the post edit screen this field is blank when going to edit a post? so i assume that the value is not being loaded from the database? how do i get hold of the database value and populate the input value? I assume i need to know how metabox populates other fields on the post edit screen?

    
    public static function html( $meta, $field ) {
        return sprintf(
            $html = '<input id="' . $targetName .'-' . $fieldType . '" type="text" name="%s" value="%s">
                    <script>
                    document.addEventListener("DOMContentLoaded", function(event) {
                        const fp = flatpickr("#calendar", 
                        {
                            dateFormat: "Y-m-d H:i",
                            altInput: true, 
                            altFormat: "d-m-Y"
                        });
                    })
                    </script>
                    ',
            $field['field_name'],
            $field['id'],
            $meta
        );
    }
    

    Thanks

    #32318
    Long NguyenLong Nguyen
    Moderator

    Hi,

    I see there are two variable placeholders in your code %s

    <input id="' . $targetName .'-' . $fieldType . '" type="text" name="%s" value="%s">
    

    If you do not need to use the field ID, please remove this variable from your code.

        return sprintf(
            $html = '<input id="' . $targetName .'-' . $fieldType . '" type="text" name="%s" value="%s">
                   ...
                    ',
            $field['field_name'],
            $meta
        );
    #32322
    Nicholas CoxNicholas Cox
    Participant

    that worked great thanks!

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