LLMS_Form_Field::get_field_html()

Retrieve the full HTML for the field.


Return Return

(string)


Top ↑

Source Source

File: includes/forms/class-llms-form-field.php

	protected function get_field_html() {

		/**
		 * Allow 3rd parties to create custom field types or their own field HTML methods.
		 *
		 * Returning a non-empty string will override default HTML generation and use the returned HTML instead.
		 *
		 * @since 5.0.0
		 *
		 * @param string          $html     Override html.
		 * @param array           $settings Array of field settings initially passed to the class constructor.
		 * @param LLMS_Form_Field $field    Form field object.
		 */
		$override = apply_filters( 'llms_form_field_get_' . $this->settings['type'] . '_html', '', $this->settings, $this );
		if ( ! empty( $override ) ) {
			return $override;
		}

		$extra_attrs  = array();
		$inner_html   = '';
		$self_closing = false;

		switch ( $this->settings['type'] ) {

			case 'button':
			case 'reset':
			case 'submit':
				$tag                 = 'button';
				$classes             = array( 'llms-field-button' );
				$inner_html          = $this->settings['value'];
				$extra_attrs['type'] = $this->settings['type'];
				break;

			case 'checkbox':
			case 'radio':
				$is_group     = ! empty( $this->settings['options'] );
				$tag          = $is_group ? 'div' : 'input';
				$self_closing = ! $is_group;
				$classes      = array( sprintf( 'llms-field-%s', $this->settings['type'] ) );

				if ( ! $is_group ) {

					$extra_attrs['type'] = $this->settings['type'];
					if ( true === $this->settings['checked'] ) {
						$extra_attrs['checked'] = 'checked';
					}
				} else {

					$classes[] = 'llms-input-group';
					$fields    = $this->explode_options_to_fields( false );
					foreach ( $fields as $field ) {
						$inner_html .= $field->get_html();
					}
				}

				break;

			case 'html':
				$tag        = 'div';
				$classes    = array( 'llms-field-html' );
				$inner_html = $this->settings['value'];
				break;

			case 'select':
				$tag        = 'select';
				$classes    = array( 'llms-field-select' );
				$inner_html = $this->get_options_html();
				break;

			case 'textarea':
				$tag        = 'textarea';
				$classes    = array( 'llms-field-textarea' );
				$inner_html = $this->settings['value'];
				break;

			default:
				$tag                 = 'input';
				$self_closing        = true;
				$classes             = array( 'llms-field-input' );
				$extra_attrs['type'] = $this->settings['type'];

		}

		$extra_attrs['class'] = implode( ' ', $this->classes_ensure_array( $this->settings['classes'], $classes ) );

		$attributes = array_merge( $this->get_html_attributes( $this->settings ), $extra_attrs );
		ksort( $attributes );

		$attrs = '';
		foreach ( $attributes as $attr => $val ) {
			$attrs .= sprintf( ' %1$s="%2$s"', $attr, $val );
		}

		$open  = $self_closing ? sprintf( '<%1$s%2$s', $tag, $attrs ) : sprintf( '<%1$s%2$s>', $tag, $attrs );
		$close = $self_closing ? ' />' : sprintf( '</%s>', $tag );

		return sprintf( '%1$s%2$s%3$s', $open, $inner_html, $close );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.2.0 Moved exploding of checkbox and radio options to explode_options_to_fields().
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.