AnsPress_Form::form_fields()

Description #

Out put all form fields based on on their type

Changelog #

VersionDescription
2.0Introduced.

Source #

File: includes/class/form.php

	private function form_fields() {
		/**
		 * FILTER: ap_pre_form_fields
		 * Provide filter to add or override form fields before output.
		 * @var array
		 * @since 2.0.1
		 */
		$this->args['fields'] = apply_filters( 'ap_pre_form_fields', $this->args['fields'] );

		foreach ( $this->args['fields'] as $field ) {

			$this->field = $field;

			$error_class = $this->have_error() ? ' ap-have-error' : '';

			if ( isset( $this->args['field_hidden'] ) && $this->args['field_hidden'] ) {
				if ( isset( $field['name'] ) && $field['type'] != 'hidden' && (@$field['visibility'] != 'me' || ( @$field['visibility'] == 'me' && $this->args['user_id'] == get_current_user_id())) ) {
					$nonce = wp_create_nonce( 'user_field_form_'.$field['name'].'_'.$this->args['user_id'] );

					$this->output .= '<div id="'.@$field['name'].'_field_wrap" class="clearfix ap-form-fields-wrap'.$error_class.'">';
						$this->output .= '<label class="ap-form-fields-wrap-label">'.@$field['label'].'</label>';
						$this->output .= '<div id="user_field_form_'.$field['name'].'" class="ap-form-fields-wrap-inner"><span>'.@$field['value'].'</apn></div>';
					$this->output .= '</div>';
				}
			} else {

				switch ( $field['type'] ) {

					case 'text':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->text_field( $field, 'text' );
						$this->output .= '</div>';
						break;

					case 'password':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->text_field( $field, 'password' );
						$this->output .= '</div>';
						break;

					case 'number':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->number_field( $field );
						$this->output .= '</div>';
						break;

					case 'checkbox':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->checkbox_field( $field );
						$this->output .= '</div>';
						break;

					case 'radio':
						$this->output .= '<div class="ap-field-'.@$field['name'] .' ap-form-fields' . $error_class .'">';
						$this->radio_field( $field );
						$this->output .= '</div>';
						break;

					case 'select':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->select_field( $field );
						$this->output .= '</div>';
						break;

					case 'taxonomy_select':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->taxonomy_select_field( $field );
						$this->output .= '</div>';
						break;

					case 'page_select':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->page_select_field( $field );
						$this->output .= '</div>';
						break;

					case 'textarea':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->textarea_field( $field );
						$this->output .= '</div>';
						break;

					case 'editor':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->editor_field( $field );
						$this->output .= '</div>';
						break;

					case 'hidden':
						$this->hidden_field( $field );
						break;

					case 'custom':
						$this->output .= '<div class="ap-field-'.@$field['name'].' ap-form-fields'.$error_class.'">';
						$this->custom_field( $field );
						$this->output .= '</div>';
						break;

					default:
						/**
						 * FILTER: ap_form_fields_[type]
						 * filter for custom form field type
						 */
						$this->output .= apply_filters( 'ap_form_fields_'.$field['type'],  $field );
						break;
				}
			}
		}
	}

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