Working …
This value you provided is not a number. Please try again.
This value you provided is not an integer. Please try again.
The value entered is not a valid Vanderbilt Medical Record Number (i.e. 4- to 9-digit number, excluding leading zeros). Please try again.
The value you provided must be within the suggested range
The value you provided is outside the suggested range
This value is admissible, but you may wish to double check it.
The value entered must be a time value in the following format HH:MM within the range 00:00-23:59 (e.g., 04:32 or 23:19).
This field must be a 5 or 9 digit U.S. ZIP Code (like 94043). Please re-enter it now.
This field must be a 10 digit U.S. phone number (like 415 555 1212). Please re-enter it now.
This field must be a valid email address (like joe@user.com). Please re-enter it now.
The value you provided could not be validated because it does not follow the expected format. Please try again.
Required format:
REDCap Logo
Plugins, Hooks, & External Modules
Developer methods for
Plugins, Hooks, & External Modules
Hook functions

REDCap Developer Tools:
Documentation for Plugins, Hooks, & External Modules

REDCap Version 14.9.1
REDCap::getValidFieldsByEvents
(REDCap >= 8.3.0)
REDCap::getValidFieldsByEvents — Returns an array of field names belonging to instruments that are designated for specified events in a longitudinal project.
Description
mixed REDCap::getValidFieldsByEvents ( int $project_id, mixed $events = NULL [, bool $includeRecordIdField = FALSE ] )
Returns an array of field names belonging to data collection instruments that are designated for specified events in a longitudinal project.
Parameters
project_id
The project ID number of the REDCap project.
events
An array of unique event names or event_id's, or alternatively a single unique event name or event_id (as a string or int, respectively). This will limit the fields returned only to forms that are designated for those events specified. By default, NULL is used, which will return the field names for all fields in the current project. If the project is not longitudinal, NULL is used.
includeRecordIdField (optional)
Set this to TRUE to additionally return the Record ID field for the project (if the Record ID field would not be returned for the events provided). By default, FALSE is used.
Return Values
Returns an array of field names belonging to data collection instruments that are designated for specified events in a longitudinal project.
Examples
Example #1:
This example returns fields for two events provided via their unique event names in an array.
$events = array('enrollment_arm_1', 'final_visit_arm_1');
$fields = REDCap::getValidFieldsByEvents($project_id, $events);
Example #2:
This example returns the Record ID field and the fields for one event provided via its unique event name as a string.
$events = 'enrollment_arm_1';
$fields = REDCap::getValidFieldsByEvents($project_id, $events, true);
Example #3:
This example returns fields for three events provided via their event IDs in an array.
$events = array(347, 350, 352);
$fields = REDCap::getValidFieldsByEvents($project_id, $events);
Example #4:
This example illustrates how to export data via getData() for only the fields in specific events.
$events = array('enrollment_arm_1', 'visit_1_arm_1');
$fields = REDCap::getValidFieldsByEvents($project_id, $events, true);
$params = array('project_id'=>$project_id, 'return_format'=>'json', 'fields'=>$fields, 'events'=>$events);
$jsonData = REDCap::getData($params);
REDCap 14.9.1 - © 2024 Vanderbilt University