stcc
Forum Replies Created
-
Hi Nitesh:
Thank you very much! I will take a look.
stcc
Hi Daniele:
The form is not public. However I can give you access to it. I can email you the user name/password if you don’t mind to give me your contact information. Please email me at: [email protected]
I really appreciate your kind help!
Hi Daniele:
You have written very great and useful codes.
The field name and the form title are all correct. …
I am not sure why it is not working. So confused.
Thank you very much!Logically it seems right for me. I am not sure if there are syntax errors inside the codes…. very confused by it not working right….
Here are the codes I slightly modified based on your code:
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)){ //An clicker with this barcode has already been returned)
$result[‘valid’] = false;
$result[‘reason’][$name] = ‘clicker already returned.’;
}
}
return $result;
}
add_filter(‘wpcf7_validate_clicker’,’duplicate_clicker_validation_filter’, 10, 2); // Email field
add_filter(‘wpcf7_validate_clicker*’, ‘duplicate_clicker_validation_filter’, 10, 2); // Req. Email fieldBy the way, if I code the above codes to the function.php file, I can just add them at the end of the function.php file, and I don’t need to put the open and close php tags, right? (only if I create a new php file to put the codes in, I will need the open and close php tags)? Thank you!
Hi Daniele:
Thank you so much for your quick reply! I have put your code in the function.php (in the theme folder), and have modified the form name, field name, error message etc according to my database structure. However, when I tried to submit the entry from my form, why it still takes/adds the duplicate entry into the database although the same entry is already in the database? I am a little bit confused so I wonder if that is the steps I should follow:
change your codes according to my formname/field
put the code in the function.php
then I am all set to test the form entry?Please correct me if I am wrong. Thank you so much!
Thank you very much for the codes! I am wondering how I should use these codes: do I put them in the function.php in the theme folder? how should I call it in the wordpress page/post so that it will work (and check if there are duplicates in the database for that particular field). I will greatly appreciate if you can give me some suggestions. Thank you very much!