: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Returns true if this contact form is identical to the submitted one.
public function is_posted() {
if ( ! WPCF7_Submission::get_instance() ) {
if ( empty( $_POST['_wpcf7_unit_tag'] ) ) {
return $this->unit_tag() === $_POST['_wpcf7_unit_tag'];
* Generates HTML that represents a form.
* @param string|array $options Optional. Form options.
* @return string HTML output.
public function form_html( $options = '' ) {
$options = wp_parse_args( $options, array(
$this->shortcode_atts = $options;
if ( 'raw_form' == $options['output'] ) {
'<pre class="wpcf7-raw-form"><code>%s</code></pre>',
esc_html( $this->prop( 'form' ) )
if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
"This contact form is available only for logged in users.",
'<p class="wpcf7-subscribers-only">%s</p>',
return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
$this->unit_tag = self::generate_unit_tag( $this->id );
$action_url = wpcf7_get_request_uri();
if ( $frag = strstr( $action_url, '#' ) ) {
$action_url = substr( $action_url, 0, -strlen( $frag ) );
$action_url .= '#' . $this->unit_tag();
$action_url = apply_filters( 'wpcf7_form_action_url', $action_url );
str_starts_with( $action_url, '//' ) or
! str_starts_with( $action_url, '/' ) and
! str_starts_with( $action_url, home_url() )
'<p class="wpcf7-invalid-action-url"><strong>%1$s</strong> %2$s</p>',
esc_html( __( 'Error:', 'contact-form-7' ) ),
esc_html( __( "Invalid action URL is detected.", 'contact-form-7' ) )
$lang_tag = str_replace( '_', '-', $this->locale );
if ( preg_match( '/^([a-z]+-[a-z]+)-/i', $lang_tag, $matches ) ) {
$html = "\n" . sprintf( '<div %s>',
wpcf7_format_atts( array(
'class' => 'wpcf7 no-js',
'id' => $this->unit_tag(),
( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
$html .= "\n" . $this->screen_reader_response() . "\n";
$id_attr = apply_filters( 'wpcf7_form_id_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $options['html_id'] )
$name_attr = apply_filters( 'wpcf7_form_name_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $options['html_name'] )
$title_attr = apply_filters( 'wpcf7_form_title_attr', $options['html_title'] );
if ( $this->is_posted() ) {
$submission = WPCF7_Submission::get_instance();
$data_status_attr = $this->form_status_class_name(
$submission->get_status()
$class .= sprintf( ' %s', $data_status_attr );
$data_status_attr = 'init';
if ( $options['html_class'] ) {
$class .= ' ' . $options['html_class'];
if ( $this->in_demo_mode() ) {
$class = explode( ' ', $class );
$class = array_map( 'sanitize_html_class', $class );
$class = array_filter( $class );
$class = array_unique( $class );
$class = implode( ' ', $class );
$class = apply_filters( 'wpcf7_form_class_attr', $class );
$enctype = wpcf7_enctype_value( apply_filters( 'wpcf7_form_enctype', '' ) );
$autocomplete = apply_filters( 'wpcf7_form_autocomplete', '' );
'action' => esc_url( $action_url ),
'class' => ( '' !== $class ) ? $class : null,
'id' => ( '' !== $id_attr ) ? $id_attr : null,
'name' => ( '' !== $name_attr ) ? $name_attr : null,
'aria-label' => ( '' !== $title_attr )
? $title_attr : __( 'Contact form', 'contact-form-7' ),
'enctype' => ( '' !== $enctype ) ? $enctype : null,
'autocomplete' => ( '' !== $autocomplete ) ? $autocomplete : null,
'data-status' => $data_status_attr,
$atts += (array) apply_filters( 'wpcf7_form_additional_atts', array() );
$html .= sprintf( '<form %s>', wpcf7_format_atts( $atts ) ) . "\n";
$html .= $this->form_hidden_fields();
$html .= $this->form_elements();
if ( ! $this->responses_count ) {
$html .= $this->form_response_output();
$html .= "\n" . '</form>';
$html .= "\n" . '</div>';
* Returns the class name that matches the given form status.
private function form_status_class_name( $status ) {
case 'validation_failed':
case 'acceptance_missing':
preg_replace( '/[^0-9a-z]+/i', '-', $status )
* Returns a set of hidden fields.
private function form_hidden_fields() {
'_wpcf7_version' => WPCF7_VERSION,
'_wpcf7_locale' => $this->locale(),
'_wpcf7_unit_tag' => $this->unit_tag(),
'_wpcf7_container_post' => 0,
'_wpcf7_posted_data_hash' => '',
$hidden_fields['_wpcf7_container_post'] = (int) get_the_ID();
if ( $this->nonce_is_active() and is_user_logged_in() ) {
$hidden_fields['_wpnonce'] = wpcf7_create_nonce();
$hidden_fields += (array) apply_filters(
'wpcf7_form_hidden_fields', array()
foreach ( $hidden_fields as $name => $value ) {
'<input type="hidden" name="%1$s" value="%2$s" />',
return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
* Returns the visible response output for a form submission.
public function form_response_output() {
$class = 'wpcf7-response-output';
if ( $this->is_posted() ) { // Post response output for non-AJAX
$submission = WPCF7_Submission::get_instance();
$status = $submission->get_status();
$content = $submission->get_response();
'class' => trim( $class ),
$output = sprintf( '<div %1$s>%2$s</div>',
wpcf7_format_atts( $atts ),
$output = apply_filters( 'wpcf7_form_response_output',
$output, $class, $content, $this, $status
$this->responses_count += 1;
* Returns the response output that is only accessible from screen readers.
public function screen_reader_response() {
$validation_errors = array();
if ( $this->is_posted() ) { // Post response output for non-AJAX
$submission = WPCF7_Submission::get_instance();
$primary_response = $submission->get_response();
if ( $invalid_fields = $submission->get_invalid_fields() ) {
foreach ( (array) $invalid_fields as $name => $field ) {
$list_item = esc_html( $field['reason'] );
'<a href="#%1$s">%2$s</a>',
esc_attr( $field['idref'] ),
$validation_error_id = wpcf7_get_validation_error_reference(
if ( $validation_error_id ) {
'<li id="%1$s">%2$s</li>',
esc_attr( $validation_error_id ),
$validation_errors[] = $list_item;
$primary_response = sprintf(
'<p role="status" aria-live="polite" aria-atomic="true">%s</p>',
esc_html( $primary_response )
$validation_errors = sprintf(
implode( "\n", $validation_errors )
'<div class="screen-reader-response">%1$s %2$s</div>',
* Returns a validation error for the specified input field.
* @param string $name Input field name.
public function validation_error( $name ) {
if ( $this->is_posted() ) {
$submission = WPCF7_Submission::get_instance();
if ( $invalid_field = $submission->get_invalid_field( $name ) ) {
$error = trim( $invalid_field['reason'] );
'class' => 'wpcf7-not-valid-tip',
'<span %1$s>%2$s</span>',
wpcf7_format_atts( $atts ),
return apply_filters( 'wpcf7_validation_error', $error, $name, $this );
* Replaces all form-tags in the form template with corresponding HTML.
* @return string Replaced form content.
public function replace_all_form_tags() {
$manager = WPCF7_FormTagsManager::get_instance();
$form = $this->prop( 'form' );
if ( wpcf7_autop_or_not() ) {
$form = $manager->replace_with_placeholders( $form );
$form = wpcf7_autop( $form );
$form = $manager->restore_from_placeholders( $form );
$form = $manager->replace_all( $form );
$this->scanned_form_tags = $manager->get_scanned_tags();
* Replaces all form-tags in the form template with corresponding HTML.
* @deprecated 4.6 Use replace_all_form_tags()
* @return string Replaced form content.
public function form_do_shortcode() {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_ContactForm::replace_all_form_tags'
return $this->replace_all_form_tags();
* Scans form-tags from the form template.
* @param string|array|null $cond Optional. Filters. Default null.
* @return array Form-tags matching the given filter conditions.
public function scan_form_tags( $cond = null ) {
$manager = WPCF7_FormTagsManager::get_instance();
if ( empty( $this->scanned_form_tags ) ) {
$this->scanned_form_tags = $manager->scan( $this->prop( 'form' ) );
$tags = $this->scanned_form_tags;
return $manager->filter( $tags, $cond );
* Scans form-tags from the form template.
* @deprecated 4.6 Use scan_form_tags()
* @param string|array|null $cond Optional. Filters. Default null.
* @return array Form-tags matching the given filter conditions.
public function form_scan_shortcode( $cond = null ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_ContactForm::scan_form_tags'
return $this->scan_form_tags( $cond );
* Replaces all form-tags in the form template with corresponding HTML.
* @return string Replaced form content. wpcf7_form_elements filters applied.
public function form_elements() {
return apply_filters( 'wpcf7_form_elements',
$this->replace_all_form_tags()
* Collects mail-tags available for this contact form.
* @param string|array $options Optional. Search options.
* @return array Mail-tag names.
public function collect_mail_tags( $options = '' ) {
$manager = WPCF7_FormTagsManager::get_instance();
$options = wp_parse_args( $options, array(
'exclude' => $manager->collect_tag_types( 'not-for-mail' ),
$tags = $this->scan_form_tags();
foreach ( (array) $tags as $tag ) {
} elseif ( ! empty( $options['include'] ) ) {
if ( ! in_array( $type, $options['include'] ) ) {
} elseif ( ! empty( $options['exclude'] ) ) {
if ( in_array( $type, $options['exclude'] ) ) {
$mailtags[] = $tag->name;
$mailtags = array_unique( $mailtags );
$mailtags = array_filter( $mailtags );