• Dusty

    (@ameliapower)


    I am trying to implement two counters on a form—one for when one event time is selected and another for a second time. Once a number of submissions are made I then want to disable that option in the drop down. I’m having trouble getting the count to increment when using the id to distinguish the two options.

    The tutorial here is helpful but the two counters example given further down the page isn’t working. Result is cf7-counter:1 and cf7-counter-1:CF7_counter_1 counter_id='2'. My code is:

    In functions file:

    ` define( ‘CF7_COUNTER’, ‘cf7-counter’ );
    define( ‘CF7_COUNTER_1’, ‘cf7-counter-1’ );

    function cf7dtx_counter($atts){
    extract( shortcode_atts( array(
    ‘counter_id’ => ‘1’,
    ), $atts ) );
    $valEight = get_option( CF7_COUNTER . $counter_id, 0) + 1;
    if ($valEight > 19){
    ?>
    <script>
    document.getElementById(‘eventTime’)[1].disabled = true;
    </script>
    <?php
    }
    return $valEight;

    }
    add_shortcode(‘CF7_counter’, ‘cf7dtx_counter’);

    function cf7dtx_increment_mail_counter(){
    $valEight = get_option( CF7_COUNTER, 0) + 1;
    update_option(CF7_COUNTER, $valEight);
    }
    add_action(‘wpcf7_mail_sent’, ‘cf7dtx_increment_mail_counter’);

    function cf7dtx_counter2($atts){
    extract( shortcode_atts( array(
    ‘counter_id’ => ‘2’,
    ), $atts ) );
    $valNine = get_option( CF7_COUNTER_1 . $counter_id, 0) + 1;
    if ($valNine > 19){
    ?>
    <script>
    document.getElementById(‘eventTime’)[2].disabled = true;
    </script>
    <?php
    }
    return $valNine;
    }
    add_shortcode(‘CF7_counter’, ‘cf7dtx_counter2’);

    function cf7dtx_increment_mail_counter2(){
    $valNine = get_option( CF7_COUNTER_1, 0) + 1;
    update_option(CF7_COUNTER_1, $valNine);
    }
    add_action(‘wpcf7_mail_sent’, ‘cf7dtx_increment_mail_counter2’);`

    And in my contact form 7, my hidden fields are:

    `[dynamichidden cf7-counter “CF7_counter counter_id=’1′ “]
    [dynamichidden cf7-counter-1 “CF7_counter_1 counter_id=’2′ “]`

    The mail receipt:

    `Count 1: [cf7-counter “CF7_counter counter_id=’1′ “]
    Count 2: [cf7-counter-1 “CF7_counter_1 counter_id=’2′ “]`
    Appreciate any help with this.

    [2]: http://sevenspark.com/tutorials/how-to-create-a-counter-for-contact-form-7

  • The topic ‘Add two counters to a contact form 7 and do something with the value using Conta’ is closed to new replies.