Search code examples
oracle-databaseoracle-apexoracle-apex-5

How to identify item values in pl/sql content after page submission?


I have created a page containing a pl/sql content region where I have created an html table. The pl/sql code to create the table and screenshot of the table is given.

The page is the 2nd page in a wizard list of total of 4 pages. So when the "Finish" button on 4th page is clicked I want to insert all the rows of this html table into a database table.

I want to know how to identify the values put in the html table and how to insert these values in a database table. Could anyone help me do this?

BEGIN
  htp.p('
    <HTML>
        <HEAD>
            <TITLE>Organization Records</TITLE>
        </HEAD>
        <BODY>
            <H1>Organization Records</H1>
            <TABLE id="DataForm" BORDER="1 " style="border-collapse: collapse; width="100%">
                <TR style="width=50%">
                    <TH>Hierarchy</TH>
                    <TH>Org Long Name</TH>
                </TR>
                <TR style="width=50%">
                    <TH><input type="text"/></TH>
                    <TH>
                        <select id="S1" name="S1">
                            <option value="id1">data1</option>
                            <option value="id2">data2</option>
                            <option value="id3">data3</option>
                        </select>
                    </TH>
                 </TR>
            </TABLE>
            <button type="button" onclick="addRow()">Add</button>
        </BODY>
    </HTML>

'); end;

pl/sql content


Solution

  • You would need to capture the values when page 2 is submitted, because they are no longer present in the HTML by the time you submit page 4.

    Change the name attribute of the select to one that APEX allows - i.e. one of "f01", "f02", ..., "f50". (See docs for details.)

    When the page is submitted, APEX will then populate a corresponding array e.g. apex_application.g_f01, apex_application.g_f02, etc.

    So all you need to do is loop through the relevant array to get the values and insert them into your table:

    for i in 1..apex_application.g_f01.count loop
       insert into mytable (value) values (apex_application.g_f01(i));
    end loop;