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_every_page_top
(REDCap >= 6.14.0)
redcap_every_page_top — Allows custom actions to be performed at the top of every page in REDCap (including plugins that render the REDCap page header)
Description
void redcap_every_page_top ( int $project_id )
Allows custom actions to be performed at the top of every page in REDCap (including plugins that render the REDCap page header). You may utilize this hook to 1) perform back-end operations, such as adding or modifying data in database tables, which can be done when the page loads or when triggered by a user action on the page via JavaScript, or 2) output custom HTML, JavaScript, and/or CSS to modify the current page in any way desired. NOTICE: Regardless of the modifications made to the REDCap user interface with this hook, the REDCap copyright statement must still be visible on every page. If the copyright statement is obscured or removed by a hook, it should be displayed somewhere else on that page using REDCap::getCopyright.
Location of Execution
The function is executed at the very top of *every* page in REDCap (right after the initial BODY tag) on project and non-project pages.
Parameters
project_id
The project ID number of the REDCap project in which the hook is being called. If this hook is called on a non-project page, project_id will be NULL.
Return Values
Nothing. Your function does not need to return anything.
Examples
Example #1:
Add some custom CSS to every page to change the style of the entire application.
function redcap_every_page_top($project_id)
{
    ?><link rel="stylesheet" type="text/css" href="/plugins/fancy/style.css" media="screen"><?php
}
Example #2:
Add some custom session variables to be used for only by specific users for every PHP script in REDCap.
function redcap_every_page_top($project_id)
{
    // Set a value based upon the logged-in user's username
    if (SUPER_USER || USERID == 'paul.harris')
    {
        // Use this session variable in other hooks to perform a specic action/behavior
        $_SESSION['show_special_features'] = true;
    }
}
Example #3:
Add some page-specific logic to perform things only for specific pages in REDCap. Note: You can use the PAGE constant to refer to specific PHP scripts within subdirctories in the REDCap version directory (e.g., redcap_vX.X.X) in which they will always have the format SubdirectoryName/my_php_script.php.
function redcap_every_page_top($project_id)
{
    // Do something on the Online Designer page
    if (PAGE == 'Design/online_designer.php')
    {
        // ...
    }

    // Do something on the File Repository page but only for a specific project
    elseif ($project_id == 759 && PAGE == 'FileRepositoryController:index')
    {
        // ...
    }
}
Example #4:
Incorporate calls to a framework or helper scripts that you wish to utilize throughout REDCap on every page.
function redcap_every_page_top($project_id)
{
    // Call the framework class (this is just an example of how this methodology *might* look)
    require "/framework_path/my_framework.php";

    // Instantiate the object to use as a global variable in other hooks or plugins throughout REDCap.
    $framework = new FrameworkObject();
}
Example #5:
This example shows a simple way of performing project-specific actions using the $project_id parameter. NOTE: This particular method is not as clean or as easy to maintain for many projects at once. See the next example for a better way to implement project-specific actions for many projects.
function redcap_every_page_before_render($project_id)
{
    // Perform certain actions for specific projects (using "switch" or "if" statements).
    switch ($project_id) {

        // Perform operations for project_id 212
        case 212:
            // do something specific for this project ...
            break;

        // Perform operations for project_id 4775
        case 4775:
            // do something specific for this project ...
            break;

        // ...
    }
}
Example #6:
A much more manageable way to perform project-specific operations for many projects at once is to create a directory structure where each project has its own subdirectory under the main Hooks directory (e.g., named "redcap/hooks/pid{$project_id}/redcap_survey_page.php"). This allows the code for each project to be sandboxed and separated and also makes it more manageable to utilize other files (e.g., PHP, HTML, CSS, and/or JavaScript files) that you can keep in the project's subdirectory (i.e., "pid{$project_id}") in the Hooks folder. Then the designated project handler PHP script can utilize any of the parameters passed in the function to perform actions specific to each project. NOTE: This example assumes that the "hooks" sub-directory is located in the same directory as the PHP file containing the Hook functions.
	
REDCap 14.9.1 - © 2024 Vanderbilt University