Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Edd92

    (@edd92)

    Thank you for your quick responce.

    I have a workaround, 12 months interval would also be a year.
    To make the form user-friendly i would like to let them pick between month, quarter, half a year or a full year.

    <label> <b>How Frequent?</b>
    Once per [select frequency "year|12" "half year|6" "quarter year|4" "month|1"]
    </label>

    The Contact form 7 will show only the first part before the pipe “|”
    see: https://contactform7.com/selectable-recipient-with-pipes/

    The expected behavior is that the value after the pipe is picked to send as frequency.

    {name: “amount”, value: “15”}
    {name: “frequency”, value: “year”}

    But the text “year” is taken instead.

    I looked into the HTML But saw that the value was the same as the name, e.g. it is an CF7 issue.

    
    <select name="frequency" class="wpcf7-form-control wpcf7-select" aria-invalid="false">
    <option value="jaar">jaar</option>
    <option value="half jaar">half jaar</option>
    <option value="kwart jaar">kwart jaar</option>
    <option value="maand">maand</option></select>
    

    I resolved it by using the following snippet in functions.php in child theme

    
    #https://stackoverflow.com/questions/48515097/cant-set-values-for-select-option-in-contact-form-7
    #made to have name|value pipes work in combination with Mollie recurring payment
    function so48515097_cf7_select_values($tag)
    {
        if ($tag['basetype'] != 'select') {
            return $tag;
        }
    
        $values = [];
        $labels = [];
        foreach ($tag['raw_values'] as $raw_value) {
            $raw_value_parts = explode('|', $raw_value);
            if (count($raw_value_parts) >= 2) {
                $values[] = $raw_value_parts[1];
                $labels[] = $raw_value_parts[0];
            } else {
                $values[] = $raw_value;
                $labels[] = $raw_value;
            }
        }
        $tag['values'] = $values;
        $tag['labels'] = $labels;
    
        // Optional but recommended:
        //    Display labels in mails instead of values
        //    You can still use values using [_raw_tag] instead of [tag]
        $reversed_raw_values = array_map(function ($raw_value) {
            $raw_value_parts = explode('|', $raw_value);
            return implode('|', array_reverse($raw_value_parts));
        }, $tag['raw_values']);
        $tag['pipes'] = new \WPCF7_Pipes($reversed_raw_values);
    
        return $tag;
    }
    add_filter('wpcf7_form_tag', 'so48515097_cf7_select_values', 10);
    

    Now the Dropdown HTML looks like this:

    
    <select name="frequency" class="wpcf7-form-control wpcf7-select" aria-invalid="false">
    <option value="12">jaar </option>
    <option value="6">half jaar </option>
    <option value="4">kwart jaar </option>
    <option value="1">maand </option>
    </select>
    

    And it made the frequency picker super userfriendly!

    I don’t need any further action from your side, just wanted to post it here in case anyone else is having the same problem

    • This reply was modified 4 years, 10 months ago by Edd92.
    • This reply was modified 4 years, 10 months ago by Edd92.
    Thread Starter Edd92

    (@edd92)

    Hi ellp,

    I’m sorry my post might not made clear what my problem is.

    The slider works fine on any device with the arrow buttons.
    But i wanted to add touch swipe funtionality to mobile devices and tablets.
    I’ve placed jquery mobile script in the footer (wich should regconize touch movement) along with a script that will link a swipe left movement to ‘next’ and a swipe right movement to ‘prev’
    Connect-ed.nl

Viewing 2 replies - 1 through 2 (of 2 total)