Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Drupal 7数据库中查询必填字段?_Drupal - Fatal编程技术网

如何在Drupal 7数据库中查询必填字段?

如何在Drupal 7数据库中查询必填字段?,drupal,Drupal,我试图编写一个函数,从drupal数据库中获取所需字段的名称。然后,我可以编写一个验证函数,提醒用户他/她没有在必填字段中输入内容。使用该函数,您可以非常轻松地获得此信息: $instances = field_info_instances('node', 'invoice'); $required = array(); foreach ($instances as $field_name => $instance) { if ($instance['required'] == 1)

我试图编写一个函数,从drupal数据库中获取所需字段的名称。然后,我可以编写一个验证函数,提醒用户他/她没有在必填字段中输入内容。

使用该函数,您可以非常轻松地获得此信息:

$instances = field_info_instances('node', 'invoice');
$required = array();
foreach ($instances as $field_name => $instance) {
  if ($instance['required'] == 1) {
    $required[] = $field_name;
  }
}
要获取字段类型,需要查询字段而不是实例。在循环中,您可以调用:

$field = field_info_field($field_name);
$type = $field['type'];

什么的必填字段?我需要知道特定内容类型的必填字段,以便我可以为每个必填字段编写一个验证函数,而不是一个。我正在尝试使用node_save()将内容从另一个CMS迁移到Drupal,但它跳过了Drupal验证。是否也有方法获取字段类型?