Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1467714

    Hi,
    i’m using contact form 7 and trying to change the colour of the * (for requiered fields to red.

    This is what i got in the form:

    <div class="form-row">
    <div class="column-half"> [text* first-name placeholder "First name *"]</div>
    <div class="column-half"> [text* last-name placeholder "Last name *"]</div>
    <div class="form-row">
    <div class="column-full"> [email* your-email placeholder "Email"]</div>
    </div>
    <div class="form-row">
    <div class="column-full"> [textarea* your-message placeholder "Your message *"]</div>
    </div>
    <div class="form-row">
    <div class="column-full">[submit "Send"]</div>
    </div>

    kind regards
    Jak

    • This topic was modified 2 months, 4 weeks ago by Jak73.
    • This topic was modified 2 months, 4 weeks ago by Jak73.
    #1467735

    Hey Jak73,

    It’s not possible to style the star only, since it’s added with the rest of the text. If you refer to the plugin documenations, then maybe there is a default way of adding a required character? Please note that we are here to support the Enfold theme, not Contact Form 7.

    Best regards,
    Rikard

    #1467821

    as placeholder text ( inside the input field ) this is hard to get.

    #1467878

    ok – if this is ok for you – see: https://webers-testseite.de/jak-contact/
    ( due to maintainance mode of my hoster – page might be not seen today )

    snippet for child-theme functions.php and the contakt form 7 Form code is on that page.

    snippet:
    (The script is necessary because CF7 does not provide a way to select whether an input field is in focus or filled.)

    function class_on_active_form_fields(){
    ?>
    <script>
    window.addEventListener("DOMContentLoaded", function () { 
      (function($) {     
        $('.wpcf7-form-control').each(function() {
          $(this).on('focus', function() {
            $(this).parent().addClass('active');
          });
          $(this).on('blur', function() {
            if ($(this).val().length == 0) {
              $(this).parent().removeClass('active');
            }
          });
        });
      })(jQuery);
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'class_on_active_form_fields');

    the css ( with your wrapper class ):

    .form-wrapper {
      position : relative !important;
    }
    
    .form-wrapper .placeholder {
      position: absolute;
      top: 5px;
      left: 5px;
      opacity: 0.5;
      transition: opacity 1s ease;
      pointer-events: none;
    }
    
    .form-wrapper .asterisk {
      color: red !important;
    }
    
    .wpcf7-form-control-wrap.active + .placeholder { 
      opacity: 0 !important;
    }

    the form in this setup:

    <div class="form-wrapper">[text* first-name placeholder ""]<span class="placeholder">First name <span class="asterisk">*</span></span></div>
    <div class="form-wrapper">[text* last-name placeholder ""]<span class="placeholder">Last name <span class="asterisk">*</span></span></div>
    <div class="form-wrapper">[email* your-email placeholder " "]<span class="placeholder">E-Mail <span class="asterisk">*</span></span></div>
    <div class="form-wrapper">[textarea* textarea-716 placeholder " "]<span class="placeholder">Placeholder <span class="asterisk">*</span></span></div>
    
    <div class="form-wrapper">[submit "Send"]</div>
    #1467891

    Genius, thank you!
    I’ll give it a try
    Jak

    #1467892

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.