Custom Fields
Re-Envisioned
Support MB Frontend Submission Unsetting fields & changing placeholder/required before rendering form

This topic contains 1 reply, has 2 voices, and was last updated by  Anh Tran 4 weeks ago.

  • Creator
    Topic
  • #16565
    Resolved
    pza
    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!

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #16585

    Anh 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 1 replies (of 1 total)

You must be logged in to reply to this topic.