Cambiare il submit di Contact Form 7
Le istruzioni seguenti sono valide per il plugin Contact Form 7, prima viene rimosso il bottone predefinito e poi viene ricostruito.
Volevo aggiungere una classe CSS che funziona male se applicata a un campo di tipo input. Con il seguente codice ho potuto convertire il campo in un tipo button.
/* change contact 7 submit from input to button */
remove_action('wpcf7_init', 'wpcf7_add_form_tag_submit');
add_action('wpcf7_init', function () {
wpcf7_add_form_tag('submit', 'zod_submit_cf7_button_handler');
});
function zod_submit_cf7_button_handler($tag) {
$tag = new WPCF7_FormTag($tag);
$class = wpcf7_form_controls_class($tag->type);
$atts = array();
$atts['class'] = $tag->get_class_option($class);
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option('tabindex', 'int', true);
$value = isset($tag->values[0]) ? $tag->values[0] : '';
if (empty($value)) {
$value = esc_html__('Send', 'hello-child');
}
$atts['type'] = 'submit';
$atts = wpcf7_format_atts($atts);
$html = sprintf( '<button %1$s>%2$s</button>', $atts, $value );
return $html;
}

Comments (0)