WPCF7_ContactForm::form_html() public CF7 1.0
Generating Form HTML
{} Это метод класса: WPCF7_ContactForm{}
Возвращает
Null. Ничего.
Использование
$WPCF7_ContactForm = new WPCF7_ContactForm();
$WPCF7_ContactForm->form_html( $args );
- $args **
- -
По умолчанию: ''
Код WPCF7_ContactForm::form_html() WPCF7 ContactForm::form html
CF7 5.4
<?php
public function form_html( $args = '' ) {
$args = wp_parse_args( $args, array(
'html_id' => '',
'html_name' => '',
'html_class' => '',
'output' => 'form',
) );
$this->shortcode_atts = $args;
if ( 'raw_form' == $args['output'] ) {
return '<pre class="wpcf7-raw-form"><code>'
. esc_html( $this->prop( 'form' ) ) . '</code></pre>';
}
if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
$notice = __(
"This contact form is available only for logged in users.",
'contact-form-7' );
$notice = sprintf(
'<p class="wpcf7-subscribers-only">%s</p>',
esc_html( $notice ) );
return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
}
$this->unit_tag = self::generate_unit_tag( $this->id );
$lang_tag = str_replace( '_', '-', $this->locale );
if ( preg_match( '/^([a-z]+-[a-z]+)-/i', $lang_tag, $matches ) ) {
$lang_tag = $matches[1];
}
$html = sprintf( '<div %s>',
wpcf7_format_atts( array(
'role' => 'form',
'class' => 'wpcf7',
'id' => $this->unit_tag(),
( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
=> $lang_tag,
'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
) )
);
$html .= "\n" . $this->screen_reader_response() . "\n";
$url = wpcf7_get_request_uri();
if ( $frag = strstr( $url, '#' ) ) {
$url = substr( $url, 0, -strlen( $frag ) );
}
$url .= '#' . $this->unit_tag();
$url = apply_filters( 'wpcf7_form_action_url', $url );
$id_attr = apply_filters( 'wpcf7_form_id_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_id'] ) );
$name_attr = apply_filters( 'wpcf7_form_name_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_name'] ) );
$class = 'wpcf7-form';
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 );
} else {
$data_status_attr = 'init';
$class .= ' init';
}
if ( $args['html_class'] ) {
$class .= ' ' . $args['html_class'];
}
if ( $this->in_demo_mode() ) {
$class .= ' demo';
}
$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 = apply_filters( 'wpcf7_form_enctype', '' );
$autocomplete = apply_filters( 'wpcf7_form_autocomplete', '' );
$novalidate = apply_filters( 'wpcf7_form_novalidate',
wpcf7_support_html5()
);
$atts = array(
'action' => esc_url( $url ),
'method' => 'post',
'class' => $class,
'enctype' => wpcf7_enctype_value( $enctype ),
'autocomplete' => $autocomplete,
'novalidate' => $novalidate ? 'novalidate' : '',
'data-status' => $data_status_attr,
);
if ( '' !== $id_attr ) {
$atts['id'] = $id_attr;
}
if ( '' !== $name_attr ) {
$atts['name'] = $name_attr;
}
$atts = wpcf7_format_atts( $atts );
$html .= sprintf( '<form %s>', $atts ) . "\n";
$html .= $this->form_hidden_fields();
$html .= $this->form_elements();
if ( ! $this->responses_count ) {
$html .= $this->form_response_output();
}
$html .= '</form>';
$html .= '</div>';
return $html;
}