AnsPress_Ajax::get_repeatable_field()

Description #

Ajax callback for returning repeatable field group.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: includes/ajax-hooks.php

	public static function get_repeatable_field() {
		if ( ! ap_verify_nonce( 'get_repeatable_field' ) ) {
			ap_ajax_json( [ 'success' => false ] );
		}

		$form_name    = ap_sanitize_unslash( 'form_name', 'r' );
		$field_name   = ap_sanitize_unslash( 'field_name', 'r' );
		$count_groups = ap_sanitize_unslash( 'current_groups', 'r' );

		$_REQUEST[ sanitize_title( $field_name ) . '-g' ] = $count_groups;
		$_REQUEST[ sanitize_title( $field_name ) . '-n' ]  = ap_sanitize_unslash( 'current_nonce', 'r' );

		$form = anspress()->get_form( 'question' );
		$form->prepare();
		$field = $form->find( $field_name );

		if ( ! empty( $field ) && is_object( $field ) ) {
			if ( $field->get_last_field() ) {
				ap_ajax_json( array(
					'success' => true,
					'html'    => $field->get_last_field()->output(),
					'nonce'    => wp_create_nonce( $field_name . ( $count_groups + 1 ) ),
				) );
			}
		}
	}

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