Custom HTML can be added around individual fields and elements in the form replacing the default HTML. Note that fields refer to the entire form field including the input element, label element, and in the case of inline errors, the error element. Elements refer to the individual parts of the field, so HTML wrapping the elements will wrap around each element individually. This PHP method, if desired, should be called after the field has been instantiated. The method has four arguments ( if the default HTML is desired for any of the arguments, the argument value should be set to “False”. “False” is the default value for each argument):
1 |
public function customHtml($open_field = false, $close_field = false, $open_html = false, $close_html = false) |
- Field opening: The first argument is the string that will be added before the field. By default, the list layout has no field opening tag and the table layout opens each field with the table row
- Field closing: The second argument is the string that will be added after the field. By default, the list layout has no field closing tag and the table layout closes each field with the table row
- Element opening: The third argument is the string that is added before each element in the field. By default, the list layout opens elements with the list item
- Element closing: The fourth argument is the string that is added after each element in the field. By default, the list layout closes elements with the list item
An example usage of this PHP method could be: A form is desired where the email field and email confirmation field are wrapped in a sub list of the field. This means that the opening field tag for the email field needs to be a list item followed by a list opening tag (to start the nested list), the email closing field tag should be empty, and the element HTML should be default. The email confirmation field opening HTML should be empty, the closing field HTML should be the closing tag of the nested list followed by the closing tag for the list item, and, the element HTML should be default:
1 2 3 4 5 6 7 8 |
// Instantiate the field $form->email = new Email(‘Please enter your email’); // Add in some custom opening tags and closing tags for the email form // Here the opening field tags are replaced with the regular li plus a nested ul. leave arguments 4,5 empty so default false is used $form->email->customHtml(‘<li><ul class=”inline-list”>’,”); // Arguments 2 – 5 specify the custom HTML in confirmation methods // Here the opening tag is empty and the closing tag closes the nested list, leave arguments 4,5 empty so default false is used $form->email->addConfirmation(‘Please confirm your email’,”,’</ul></li>’); |