Custom Fields
Re-Envisioned
Support MB Frontend Submission Labels should include required info, when it’s a required field

  • Creator
    Topic
  • #17282
    Resolved flowdee
    Participant

    When setting a field to “required”, on the frontend submission form, the label should represent this state as well.

    e.g. by holding a litte span like <span class="req">*</span>. If you don’t need it, you could easily hide it via CSS.

    https://prnt.sc/q4wsia

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #17283
    flowdee
    Participant

    Temporarily solved it wthis way:

    /**
     * Maybe add required span to labels
     */
    add_filter( 'rwmb_begin_html', function ( $begin, $field, $meta ) {
     
        if ( is_admin() )
            return $begin;
     
        if ( ! empty ( $field['required'] ) ) {
            $begin = str_replace( '</label>', '<span class="req">*</span></label>', $begin );
        }
     
        return $begin;
    }, 10, 3 );

    Additional question: Tried to apply this hook only to the frontend submission fields, by using filters/prefixes like rwmb_frontend_begin_html, mb_frontend_begin_html, rwmb_mb_frontend_begin_html but none of them worked.

    #17316
    Anh Tran
    Keymaster

    Hi,

    This is fixed.

    Your filter also works. If you want to make it work only on the front end, you need to check with is_admin() function. There is no filters like rwmb_frontend_*.

    #17319
    flowdee
    Participant

    Perfect, thanks!

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