Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function is_clicker_already_returned($myclicker){ // Check if a clicker already returned
- global $wpdb;
- define ('FORM_NAME', 'Clickers Inventory');
- define ('FIELD_NAME', 'Clicker');
- $query="SELECT submit_time,
- if(field_name='".FIELD_NAME."', field_value, null ) AS '".FIELD_NAME."'
- FROM wp_cf7dbplugin_submits
- WHERE form_name = '".FORM_NAME."' AND field_value='".$myclicker."'";
- $myrows = $wpdb->get_results( $query, ARRAY_A );
- if (is_array($myrows) && count($myrows)){
- return true; //clicker already exists in the db
- }else{
- return false; // first time with this email
- }
- }
- function duplicate_clicker_validation_filter($result,$tag){
- define ('FIELD_NAME', 'Clicker');
- $type = $tag['type'];
- $name = $tag['name'];
- if($name == FIELD_NAME){ // Only apply to fields with the form field name of "clicker"
- $the_value = $_POST[$name];
- if(is_clicker_already_returned($the_value)){ //A clicker with this barcode has been returned)
- $result['valid'] = false;
- $result['reason'][$name] = 'clicker already returned.';
- }
- }
- return $result;
- }
- add_filter('wpcf7_validate_clicker','duplicate_clicker_validation_filter', 10, 2); // clicker field
- add_filter('wpcf7_validate_clicker*', 'duplicate_clicker_validation_filter', 10, 2); // Req. clicker field
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement