Unsetting fields & changing placeholder/required before rendering form

Support MB Frontend Submission Unsetting fields & changing placeholder/required before rendering formResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16565
    pzapza
    Participant

    I'm having w/this: I want to dynamically change form field attributes on a Frontend Submission form. I mean fields, not the shortcode attrs like "post_title" etc. I'm making metaboxes with MB builder.

    Using action rwmb_frontend_before_form I am able to set field default values with rwmb_{fieldid}_field_meta filter.

    BUT I also want to change "required" & "placeholder" , and conditionally remove some fields.

    I tried using the rwmb_normalize_{fieldid}_field filter but it doesn't work. Maybe I'm thinking of this wrong.

    Can you please suggest how I can conditionally remove fields on a FES form, and change field placeholder/required attributes?

    Thanks!

    #16585
    Anh TranAnh Tran
    Keymaster

    Hi @pza, I'm thinking about using some code like this:

    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $fields = [];
    
        if ( ! is_admin() ) {
            $fields[] = [...]; // A front-end-only field.
        }
    
        $text_field = [
            'id' => 't',
            'name' => 'Text',
        ];
        if ( ! is_admin() ) {
            $text_field['required'] = true; // Change field settings only on the front end.
        }
    
        $fields[] = $text_field;
    
        $meta_boxes[] = [
            'id' => 'custom-mb',
            'title' => 'Custom Meta Box',
            'fields' => $fields,
        ];
    } );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.