Fork me on GitHub

Nibble Development

Nibble Development

PHP classes and libraries for developers

Custom HTML around form fields

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. 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
  2. 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
  3. 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
  4. 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:

 

Luke Rotherfield

Freelance PHP Developer
is a PHP developer dedicated to writing the most awesome liraries for his fellow devs :) enjoy

Latest posts by Luke Rotherfield (see all)

Leave a Comment