Stumbled upon something called strtolower. Works — except when corresponding input field is left empty returns big error message “Warning: strtolower() expects parameter 1 to be string, array given in …” No harm to functionality, just ugly and scary to users. Is there a way to avoid/suppress that message — or another method to do an exact match that is not case sensitive?
‘<form action=”” method=”POST”>Zip Code: <input type=”text” name=”zip5″ /> Last Name: <input type=”text” name=”last-name” /> First Name: <input type=”text” name=”first-m” /> <input type=”hidden” name=”x” value=”1″/> <input type=”submit” /> </form>’
‘[cfdb-datatable form=”my-form2″ show=”date,last-name,first-m,city,state,zip5″ filter=”zip5=$_POST(zip5)&&strtolower(last-name)=strtolower($_POST(last-name))&&first-m~~/$_POST(first-m).*/i&&intval(1)=$_POST(x)” ]’
Please, any ideas, anyone, how to to search by exact match but not be case sensitive? Or how to suppress the above error message would do. Or maybe how to force a letter in the input field when the user does not, to prevent the empty-field error message? Or maybe how to require that field (or rather two fields at the same time) have something in it before a search will run? Any workarounds? Have come a long way but always there is more, PHP/Java is yet on my horizon. Thank you!
You can use the regex without the “.*”s in it:
filter="zip5~~/^$_POST(zip5)$/i&&last-name~~/^$_POST(last-name)$/i&&first-m~~/^$_POST(first-m)$/i&&intval(1)=$_POST(x)"
But you you have to fill in values for all the fields. If you leave a field blank, it searches for a blank.
That will give you case-insensitive but if someone puts “.*” in those fields, then is shows everything.
You can also create a custom filter function in PHP to enforce the logic you want exactly.
This code might do what you want.
require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php');
function match_search_fields($entry) {
$form_fields = array('zip5', 'last-name', 'first-m');
$num_fields_filled_out = 0;
foreach ($form_fields as $field) {
if (isset($_REQUEST[$field]) && $_REQUEST[$field]) {
if (strtolower($_REQUEST[$field]) != strtolower($entry[$field])) {
return false;
}
$num_fields_filled_out++;
}
}
if (! $num_fields_filled_out) {
// Don't match if nothing in the form was filled out
return false;
}
return true;
}
cfdb_register_function('match_search_fields');
Shortcode is:
[cfdb-datatable form="my-form2" show="date,last-name,first-m,city,state,zip5" filter="match_search_fields()" ]
And you don’t need the “x” field in the search form.
Thank you! That is a nice chunk of help. Cannot test until next week, going live with what we’ve got then patch it up on the other side after all else shakes out. Many thanks.