addElement('text', 'username'); // Add a label to the text input field $form->addLabel('Enter your username:', 'username'); // Display the form $form->display(); ?>
addElement('checkbox', 'newsletter', 'Subscribe to newsletter'); // Add a label to the checkbox field $form->addLabel('Subscribe to our newsletter:', 'newsletter'); // Display the form $form->display(); ?>In this example, the addElement function is used to create a checkbox field with the name "newsletter" and label text "Subscribe to newsletter". Then the addLabel function is used to add a label to the field with the text "Subscribe to our newsletter:". The label is associated with the field using the field's name.