Contact Form 7, Modify submit button with PHP, Sage 9

Just leaving this here as someone else might find this useful, I needed to add a font awesome icon into the submit buttons on my contact 7 forms.

This theme was made using Sage Roots 9.

If you use a filter like the following within your -> App -> filters.php file it will let you mod the PHP somewhat. See Below:

add_action('init', function () {
    \wpcf7_add_form_tag('submit', function ($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_option('id', 'id', true);
        $atts['tabindex'] = $tag->get_option('tabindex', 'int', true);

        $value = isset($tag->values[0]) ? $tag->values[0] : '';

        if (empty($value))
            $value = __('Test', 'wpcf7');

        $atts['class'] = 'button';
        $atts['type'] = 'submit';
        $atts['value'] = $value;

        $atts = \wpcf7_format_atts($atts);

        $html = sprintf('', $atts, $value);

        return $html;
}, 5);

Leave a Reply

Your email address will not be published. Required fields are marked *