AnsPress_Form::checkbox_field( array $field = array() )

Description #

Checkbox field.

Parameters #

  • $field
    array (Optional) Field. Default value: array()

Changelog #

VersionDescription
2.0.1Introduced.

Source #

File: includes/class/form.php

	private function checkbox_field( $field = array() ) {
		if ( isset( $field['label'] ) ) {
			$this->label();
		}

		$this->output .= '<div class="ap-form-fields-in">';

		if ( ! empty( $field['desc'] ) ) {
			$this->output .= '<label for="' . $field['name'] . '">';
		}

		$this->output .= '<input id="' . $field['name'] . '" type="checkbox" class="ap-form-control" value="1" name="' . $field['name'] . '" ' . checked( (bool) $field['value'], true, false ) . ' ' . $this->attr( $field ) . ' />';

		// Hack for getting value of unchecked checkbox.
		$this->output .= '<input type="hidden" value="0" name="_hidden_' . $field['name'] . '" />';

		if ( ! empty( $field['desc'] ) ) {
			$this->output .= $field['desc'] . '</label>';
		}

		$this->error_messages();

		$this->output .= '</div>';
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment