Adding custom values to Contact Form 7

by | May 19, 2020 | IT Tips, Wordpress | 0 comments

From the above URL is this code. Just putting it here so I can find it again

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
  
add_action('wpcf7_init', 'custom_code_generator');
  
function custom_code_generator(){
    wpcf7_add_form_tag('coupon_code', 'custom_code_handler');
}
  
function custom_code_handler($tag){
    $input_code_name = 'your_input';
  
    $charsList = '1234567890abcdefghijklmnopqrstuvwxyz';
  
    $randomString = '';
  
    //change the value of i to meet your requirements
    for ($i=0; $i < 10; i++){
        $randomString .= $charsList[rand(0, strlen($charsList))];
    }
  
    $finalCode = strtoupper($randomString);
  
    //create html and return
  
    $html = '<input type="hidden" name="'.$input_code_name.' "value=" '.$finalCode . ' " />';
  
    return $html;
  
}

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.