Make only specific fields editable in frontend

Support MB Frontend Submission Make only specific fields editable in frontendResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33665
    hdateam90@gmail.com[email protected]
    Participant

    Is there a way to disable specific input fields in the frontend submission form?
    I only want some specific fields editable.

    I think i cant solve it with javascript easy, because, the ids of an input change from post to post i think?

    #33716
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can use the field setting disabled and set it to true to disable a field. Read more on the documentation https://docs.metabox.io/field-settings/#field-specific-settings

    [
        'name'          => __( 'Text', 'your-text-domain' ),
        'id'            => $prefix . 'text_c2x12ryc1qu',
        'type'          => 'text',
        'disabled'      => true,
    ],
    #33745
    hdateam90@gmail.com[email protected]
    Participant

    Okay, i've tried that.
    But then i cant fill the field, when i create a post?

    I want to fill it, but dont edit/change it when it is created on the frontend.
    Or do i miss something?

    Thanks.

    #33787
    Long NguyenLong Nguyen
    Moderator

    Hi,

    When registering the meta box, you can create a variable $disabled, set it to false by default and check if it is the admin area, change this variable to true to disable editing. It would be:

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $disabled = false;
        if( is_admin() ) $disabled = true;
    
        $meta_boxes[] = [
            ...
            'fields' => [
                [
                    'id'      => 'text',
                    'name'    => 'Text',
                    'type'    => 'text',
                    'disabled' => $disabled
                ],
            ],
        ];
        return $meta_boxes;
    } );
    #33792
    hdateam90@gmail.com[email protected]
    Participant

    Hi ,

    thank you. I've finished it with following code:

    add_filter( 'rwmb_normalize_vorname_field', function( $field ) {
        
    
         if( is_admin() ) {
             $field['disabled'] = false;
             
         }else{
            $field['disabled'] = true; 
         }
    
        return $field;
    } );
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.