Skip to content

How to add selected attribute to specific options in a checkbox group. #8

@richardsweeney

Description

@richardsweeney

I can create a checkbox group like so:

$checkboxes = WP_Form_Element::create( 'checkboxes' )
    ->set_name( 'interests' )
    ->set_label( 'Interests' )
    ->add_option( 'something,'Something' )
    ->add_option( 'something_else', Something else' );

Cool.

But if I'm grabbing data from the database (after the form has been submitted), how do I show which options have been selected.

$checkboxes->set_attribute( 'checked', 'checked' );

Will sets all the attributes to checked. There doesn't seem to be anything I can find in the docs about this. Any tips!?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions