[英]How can I query for required fields in a Drupal 7 Database?
I am trying to write a function that will get me the names of the required fields from the drupal database. 我正在尝试编写一个函数,该函数将从drupal数据库中获取所需字段的名称。 Then, so I can write one validation function for alerting the user that he/she has not entered in a required field.
然后,我可以编写一个验证功能来提醒用户他/她尚未在必填字段中输入。
You can get this quite easily using the field_info_instances()
function: 您可以使用
field_info_instances()
函数轻松获得此信息:
$instances = field_info_instances('node', 'invoice');
$required = array();
foreach ($instances as $field_name => $instance) {
if ($instance['required'] == 1) {
$required[] = $field_name;
}
}
To get the field type you need to query for the field not the instance. 要获取字段类型,您需要查询字段而不是实例。 In the loop you can call:
在循环中,您可以调用:
$field = field_info_field($field_name);
$type = $field['type'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.