Automattic\WooCommerce\Blocks\BlockTypes\AddToCartWithOptions

AddToCartWithOptions::has_form_elementspublicWC 1.0

Check if HTML content has form elements.

Method of the class: AddToCartWithOptions{}

No Hooks.

Returns

true|false. True if the HTML content has form elements, false otherwise.

Usage

$AddToCartWithOptions = new AddToCartWithOptions();
$AddToCartWithOptions->has_form_elements( $html_content );
$html_content(string) (required)
The HTML content.

AddToCartWithOptions::has_form_elements() code WC 10.3.6

public function has_form_elements( $html_content ) {
	$processor     = new \WP_HTML_Tag_Processor( $html_content );
	$form_elements = array( 'INPUT', 'TEXTAREA', 'SELECT', 'BUTTON', 'FORM' );
	while ( $processor->next_tag() ) {
		if ( in_array( $processor->get_tag(), $form_elements, true ) ) {
			return true;
		}
	}
	return false;
}