Search This Blog

Showing posts with label FILL a Form with data from in an URL. Show all posts
Showing posts with label FILL a Form with data from in an URL. Show all posts

Monday, June 30, 2025

How do I FILL a Form with data from in an URL

 Using Oracle APEX, you can fill a form with data passed through URL parameters, enabling dynamic and context-sensitive page behavior. This technique allows developers to pre-populate form fields based on values included in the URL, streamlining user input and improving navigation between pages. By capturing these parameters and mapping them to form items, you create a seamless experience where forms are automatically filled with relevant data upon page load, reducing manual entry and potential errors.

To fill a form with data from a URL in Oracle APEX, you leverage URL parameters to pass values into page items, which are the fields on your form. This method allows you to pre-populate form fields dynamically when the page loads, improving user experience by reducing manual data entry and enabling seamless navigation between related pages.

Steps to Fill a Form with Data from a URL:

  1. Identify the Form Page and Items
    First, determine which page contains the form you want to populate. Note the page number and the names of the form items (e.g., P10_FIRST_NAME, P10_LAST_NAME) you want to fill.

  2. Construct the URL with Parameters
    Create a URL that passes values to these form items using the syntax:
    f?p=App_ID:Page_ID:Session_ID::Request:Debug:ClearCache:item_names:item_values
    For example, to fill the form on page 10 with first name “John” and last name “Doe”:

    f?p=100:10:&SESSION.::NO::P10_FIRST_NAME,P10_LAST_NAME:John,Doe
    

    Here, 100 is the application ID, 10 is the form page number, and &SESSION. is a substitution for the current session ID.

  3. Configure Page Items to Accept URL Values
    Ensure the form page items are set to “Source” type “Always, replacing any existing value.” This allows the page items to accept and display the values passed via URL every time the page is loaded.

  4. Use Branches or Processes if Needed
    If additional processing or validation is required based on the passed data, use page processes or branches to handle that logic during page load or submission.

  5. Test the URL
    Navigate to the constructed URL in your browser. The form should open with the specified fields pre-filled with the values passed in the URL.

Additional Tips:

  • Make sure item names in the URL exactly match the page item names.

  • Use URL encoding if parameter values contain special characters or spaces.

  • This technique is often used in master-detail pages or when linking from summary reports to detailed edit forms.

By using URL parameters to fill form fields, you provide users with a faster, more intuitive workflow, reducing errors and improving overall application usability.

Example

Filling a Form with Data from a URL in Oracle APEX

Oracle APEX allows passing values through the URL to populate form fields dynamically. This is useful for pre-filling forms based on user selections or external links.

How URL Parameters Work in APEX

APEX uses the following URL structure to pass values:

f?p=App_ID:Page_ID:Session:Request:Debug:ClearCache:itemNames:itemValues

  • App_ID - The Application ID

  • Page_ID - The Page Number where the form exists

  • Session - The session value (use &SESSION. to auto-populate)

  • Request - Can be used for button processing or custom actions

  • Debug - Debug mode (set to NO or YES)

  • ClearCache - Clears session values (RP for resetting page items)

  • itemNames - The page item(s) to set values for

  • itemValues - The corresponding values for those items

Method 1: Pre-Filling a Form Using URL Parameters

If you have a form on Page 2 with fields P2_NAME and P2_EMAIL, you can pre-fill them using a URL like this:

f?p=100:2:&SESSION.::NO:RP:P2_NAME,P2_EMAIL:John,Doe@example.com

When users visit this URL, the P2_NAME field will be set to John, and the P2_EMAIL field will be set to Doe@example.com.

Steps to Implement

  1. Create a Form Page in APEX with items like P2_NAME and P2_EMAIL.

  2. Ensure these fields have Source set to Only When Current Value is Null to allow URL values.

  3. Share the generated URL for pre-filling the form.

Method 2: Using JavaScript to Read URL Parameters

If you need to process URL parameters dynamically, use JavaScript.

Step 1: Add JavaScript to Your Form Page

Go to Page Designer > Execute When Page Loads, then insert:

function getParameterByName(name) {

    let url = new URL(window.location.href);

    return url.searchParams.get(name);

}


let nameValue = getParameterByName("P2_NAME");

let emailValue = getParameterByName("P2_EMAIL");


if (nameValue) {

    $s("P2_NAME", nameValue);

}

if (emailValue) {

    $s("P2_EMAIL", emailValue);

}

Step 2: Test the URL

Use this URL format to test:

f?p=100:2:&SESSION.::NO:RP:P2_NAME,P2_EMAIL:John,Doe@example.com

This will extract values from the URL and fill the form fields using JavaScript.

Method 3: Using PL/SQL to Process URL Parameters

Sometimes, you may want to process URL parameters before displaying them on the form. You can do this using a Before Header PL/SQL Process.

Steps to Implement

  1. In Page Designer, go to Processing > Before Header.

  2. Create a new PL/SQL Process with this code:

BEGIN

    :P2_NAME := NVL(:P2_NAME, 'Default Name');

    :P2_EMAIL := NVL(:P2_EMAIL, 'default@example.com');

END;

  1. Save and Run the page.

If values are not passed in the URL, the fields will use the default values.

Best Practices

  • Use URL Encoding: If passing values that contain special characters (&, ?, /), encode them using JavaScript’s encodeURIComponent().

  • Security Considerations: Do not pass sensitive information (like passwords) in URLs. Use session state protection for security.

  • Clear Cache if Needed: If a user reloads the page, cached values may persist. Use RP in the URL to reset fields.

Filling a form with data from a URL in Oracle APEX is a simple yet powerful way to enhance user experience. You can use direct URL parameters, JavaScript, or PL/SQL depending on your requirements.

EXAMPLE:

Forms do not operate like a classic report. In order to make a form fill with data you need to create a “Pre-rendering” process that will fire off the loading of data.

In this example we are using the EMPLOYEES table provided with APEX. For our test there is an initiating page that has a link that  has two values:

  • The textbox that we are passing the data into. In this case “P10_EMPNO”.

  • The value that we are passing into that textbox. In this case “EMPNO”.

The code that we are using to generate the link looks something like the following code:

select "EMPNO",

    null LINK_CLASS,

    apex_page.get_url(p_items => 'P10_EMPNO', p_values => "EMPNO") LINK,

    null ICON_CLASS,

    null LINK_ATTR,

    null ICON_COLOR_CLASS,

    case when coalesce(:P9_EMPNO,'0') = "EMPNO"

      then 'is-active' 

      else ' '

    end LIST_CLASS,

    (substr("ENAME", 1, 50)||( case when length("ENAME") > 50 then '...' else '' end )) LIST_TITLE,

    (substr("JOB", 1, 50)||( case when length("JOB") > 50 then '...' else '' end )) LIST_TEXT,

    null LIST_BADGE

from "EMP" x

where (:P9_SEARCH is null

        or upper(x."ENAME") like '%'||upper(:P9_SEARCH)||'%'

        or upper(x."JOB") like '%'||upper(:P9_SEARCH)||'%'

    )

order by "ENAME"

Step 1 – Add a form to an empty page

  • On the body of the page right click and then select Create Region.

A screenshot of a computer

Description automatically generated

  • Make the region a form and name it Form Region

A black and grey striped background

AI-generated content may be incorrect.

  • Select the data table name

A screenshot of a computer

Description automatically generated

Step 2 – Create a process

  • At the Pre-Rendering section right click Create Process

A screenshot of a computer

AI-generated content may be incorrect.

  • Select Type : “Form-Initialization” and select the appropriate form region name

A screenshot of a computer

Description automatically generated

  • Make sure that the Execution is as follows

A screenshot of a computer

Description automatically generated

Step 3 – Set the page Security to “Unrestricted”

A screenshot of a computer

AI-generated content may be incorrect.

A screenshot of a computer

AI-generated content may be incorrect.

Step 4 – Set the receiving control Security to “Unrestricted”

A screenshot of a computer

AI-generated content may be incorrect.

A screenshot of a computer

AI-generated content may be incorrect.

That’s it. It should work.

A screenshot of a phone

AI-generated content may be incorrect.

A screenshot of a login

AI-generated content may be incorrect.

In conclusion, filling a form with data from a URL in Oracle APEX is a powerful method to enhance user interaction and application efficiency. By leveraging URL parameters and page item mappings, developers can create responsive forms that adapt to different scenarios and inputs. This approach not only saves time but also ensures data consistency and improves overall user satisfaction within the application.