我正在尝试创建一个函数来检查gform是否有一些条目、是否有所有条目或是否为空,并根据状态返回$status。
我遍历了这些条目,并检查如果为空,它们实际上是否显示为空字符串,但我只得到了部分或空。
function set_form_status($form_id) {
$entries = GFAPI::get_entries( $form_id, entry_search_criteria());
$status = '';
if (count($entries) > 0) {
foreach($entries as $entry) {
$keys = array_keys($entry);
foreach($keys as $key) {
if ($entry[$key] === '') {
$status = 'partial';
}
if ($entry[$key] !== '') {
$status = 'filled';
}
}
}
} else {
$status = 'empty';
}
return $status;
}发布于 2020-02-04 21:24:24
我建议像下面这样运行它,看看会返回什么。我确实删除了entry_search_criteria函数,但除此之外,我只是回显了键/值。
我发现,即使我没有在表单中使用purchasing,也有为它创建的字段,它们是空的。即使我选择了显示空字段,它们也不会显示在后端条目视图中。您可能会遇到类似的情况。
function set_form_status($form_id) {
$entries = GFAPI::get_entries( $form_id);
$status = '';
if (count($entries) > 0) {
foreach($entries as $entry) {
$keys = array_keys($entry);
foreach($keys as $key) {
echo $key . ' - ' . $entry[$key] . '<br>';
if ($entry[$key] === '') {
$status = 'partial';
}
if ($entry[$key] !== '') {
$status = 'filled';
}
}
}
} else {
$status = 'empty';
}
return $status;
}发布于 2020-02-05 15:24:38
和一个同事一起做了一些重构和调试,所有的表单上都有HTML字段,并且它们都返回一个空字符串。这是工作版本。
function set_form_status($form) {
define('FORM_EMPTY', 0);
define('FORM_PARTIAL', 1);
define('FORM_FILLED', 2);
//checks if the form is my special kind of form
if (is_eligible_form($form)) {
$earlier_entry = get_last_entry($form['id']);
if ($earlier_entry === false) {
return STATUS_EMPTY;
} else {
foreach($form['fields'] as $key => $field) {
if ($earlier_entry[$field->id] === '' && $field->type !== 'html') {
return FORM_PARTIAL;
}
}
}
}
return FORM_FILLED;
}https://stackoverflow.com/questions/60057909
复制相似问题