【发布时间】:2017-01-01 00:18:42
【问题描述】:
我有以下(部分)代码,它将检查在数组中输入的值(如优惠券代码检查)。如果表单中输入的值是数组中的值之一,则人们可以在表单中输入代码。
if(!in_array($posted_value, array('DA001','DA002'))){ //
所以我有一个包含 80.000 个代码的 csv 文件。无论如何(在线转换器或其他东西)我可以将所有代码放在 ' ' 和 a 之间,所以现在的 csv 是:
DA001
DA002
DA003
IE302
我想把它转换成'DA001´, 'DA002', 'DA003', 'IE302'
--- 这是我的完整代码,包括您的代码: 我将代码.csv 与 .php 文件放在同一目录中 这是我现在的代码,但是由于我有 500 个服务器错误,所以出了点问题。
add_filter('frm_validate_field_entry', 'my_custom_validation', 10, 3);
function my_custom_validation($errors, $posted_field, $posted_value){
if($posted_field->id == 9){ //change 25 to the ID of the field to validate
$codes = file("codes.csv", FILE_IGNORE_NEW_LINES);
if (!in_array($posted_value, static $codes = array_flip(...);))){ //change 001 and 002 to your allowed values
//if it doesn't match up, add an error:
$errors['field'. $posted_field->id] = 'Deze code is al een keer gebruikt of bestaat niet.';
}
}
return $errors;
}
【问题讨论】:
-
我觉得你需要一个数据库。
-
我在特定的网络服务器上没有添加另一个数据库的选项。不幸的是