Advertisement
Guest User

Untitled

a guest
Aug 8th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. function is_clicker_already_returned($myclicker){ // Check if a clicker already returned
  2. global $wpdb;
  3. define ('FORM_NAME', 'Clickers Inventory');
  4. define ('FIELD_NAME', 'Clicker');
  5. $query="SELECT submit_time,
  6. if(field_name='".FIELD_NAME."', field_value, null ) AS '".FIELD_NAME."'
  7. FROM wp_cf7dbplugin_submits
  8. WHERE form_name = '".FORM_NAME."' AND field_value='".$myclicker."'";
  9. $myrows = $wpdb->get_results( $query, ARRAY_A );
  10. if (is_array($myrows) && count($myrows)){
  11. return true; //clicker already exists in the db
  12. }else{
  13. return false; // first time with this email
  14. }
  15. }
  16. function duplicate_clicker_validation_filter($result,$tag){
  17. define ('FIELD_NAME', 'Clicker');
  18. $type = $tag['type'];
  19. $name = $tag['name'];
  20. if($name == FIELD_NAME){ // Only apply to fields with the form field name of "clicker"
  21. $the_value = $_POST[$name];
  22. if(is_clicker_already_returned($the_value)){ //A clicker with this barcode has been returned)
  23. $result['valid'] = false;
  24. $result['reason'][$name] = 'clicker already returned.';
  25. }
  26. }
  27. return $result;
  28. }
  29. add_filter('wpcf7_validate_clicker','duplicate_clicker_validation_filter', 10, 2); // clicker field
  30. add_filter('wpcf7_validate_clicker*', 'duplicate_clicker_validation_filter', 10, 2); // Req. clicker field
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement