Submitting a dynamically created form with radio buttons
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Submitting a dynamically created form with radio buttons

  1. #1
    Join Date
    Mar 2001
    Location
    New York , New York
    Posts
    577
    I am creating a web page which dynamically creates a set of Radio Buttons based on a query. This is basically to rank the various values in a table.

    I am dynamically creating radio button groups and the radio button names are also dynamically created. My problem is that when i hit the submit button it needs to call a different stored procedure to insert/update the rankings and for that the input parameters in the called procedure should be exactly same in type and number as the parameteres passed when pressing the formsubmit button.

    Since I am creating the radio buttons on the fly i dont know before hand how many sets of radio buttons will be there and hence i cannot determine what the input parameters for the called procedure should be. Is there any workaround for this kind of a problem. Please suggest.

    Also i am attaching the code which i am using to generate the radio buttons.

    CODE
    ---------
    create or replace package codb_industryoperations as
    procedure rankindustry_operations;
    function generateRadio(p_radioName in Varchar2,p_value in Number,p_attributes
    in varchar2) return varchar2;
    end codb_industryoperations;
    /
    show errors


    create or replace package body codb_industryoperations as

    procedure rankindustry_operations is

    cursor industryCntCursor is select * from lkp_industry;

    cursor operationsCntCursor (c_industry_id in number) is select a.operations_id,a.description from lkp_operations a , int_industry_operations b
    where a.operations_id=b.operations_id and b.industry_id = c_industry_id;

    begin
    htp.print(head_title('Rank Industries/Operations'));
    htp.br;
    htp.br;
    htp.formOpen(curl => owa_util.get_owa_service_path||'codb_industryoperations.setRanks',cmethod => 'Post');

    for i in industryCntCursor loop
    htp.tableOpen;

    htp.tableRowOpen;


    htp.tableRowOpen;
    htp.tableData(generateRadio('PeerIndustry',2,'Enabled'));
    htp.tableData(head_small(i.Description));
    htp.tableData(generateRadio('ind'||i.industry_id,2,'Enabled'));
    htp.tableData(generateRadio('ind'||i.industry_id,3,'Enabled'));
    htp.tableData(generateRadio('ind'||i.industry_id,4,'Enabled'));
    htp.tableData(generateRadio('ind'||i.industry_id,5,'Enabled'));
    htp.tableData(generateRadio('ind'||i.industry_id,6,'Enabled'));
    htp.tableData(generateRadio('ind'||i.industry_id,7,'Enabled'));
    htp.tableRowClose;

    for j in operationsCntCursor(i.industry_id) loop
    htp.tableRowOpen;
    htp.tableData('');
    htp.tableData(j.description);
    htp.tableData(generateRadio('oper'||j.operations_id,2,'Enabled'));
    htp.tableData(generateRadio('oper'||j.operations_id,3,'Enabled'));
    htp.tableData(generateRadio('oper'||j.operations_id,4,'Enabled'));
    htp.tableData(generateRadio('oper'||j.operations_id,5,'Enabled'));
    htp.tableData(generateRadio('oper'||j.operations_id,6,'Enabled'));
    htp.tableData(generateRadio('oper'||j.operations_id,7,'Enabled'));
    htp.tableRowClose;
    end loop;

    htp.tableClose;
    htp.br;
    htp.br;
    end loop;

    htp.formClose;
    end rankindustry_operations;

    Function generateRadio(p_radioName in varchar2,p_value in Number,p_attributes
    in varchar2) return varchar2 is
    v_radio varchar2(4000);
    Begin
    v_radio := htf.formradio(cname => p_radioName,cvalue => p_value,cattributes =>
    p_attributes);
    return v_radio;
    End generateRadio;

    end codb_industryoperations;
    /
    show errors

    Thanks
    Ronnie

  2. #2
    Join Date
    Sep 2001
    Posts
    15

    Lightbulb

    ronnie,

    first of all, there is a feature in OAS4 and 9iAS called Flexible Parameter Passing. Implementation is slightly different in OAS4 and 9iAS, but the idea is the same: you create a procedure with two in arrays for parameter names and parameter values. 9iAS requires you to prepend this procedure name with exclamation sign in HTML form action attribute so that it will know that it should use flexible parameter passing for this procedure. OAS4 automatically determined if the procedure uses fpp by doing a DESCRIBE on it. Since you are probably using 9iAS, here's example for it:

    type vc_array is table of varchar2(32767) index by binary_integer;
    procedure formHandler( names in vc_array, vals in vc_array)
    is
    begin
    for i in names.first..names.last loop
    -- process parameters here depending on their names
    ....
    end loop;
    end;

    Now to use this procedure for form processing, issue this HTML:


    <form name="form1" action="!formHandler" method="POST" enctype="multipart/formdata">
    <!-- any number of form parameters with any names/types here -->
    .....
    </form>

    Note that using enctype of "multipart/formdata" allows you to include <INPUT type=FILE> elements which will allow you to upload files to the form (read 9iAS OWA documentation for more information on prerequisites and processing of file uploads).

    Dynamic PSP, the product we offer for rapid web applications development in Oracle8i/9i goes even further than the example above. PSP stands for PL/SQL server pages. Dynamic PSP allows you to create HTML with embedded PL/SQL code for dynamic content, forms processing and various other things. All such pages are stored within the database and are called DPSP objects. Each object can accept unlimited number of parameters (Dynamic PSP extensively uses flexible parameter passing). There are also several predefined functions defined in DPSP core designed to allow developers to reuse objects, retrieve object output for post-processing, debugging and profiling.

    Example of the same code as above in DPSP object:

    <%!
    param1 varchar2(1000) := param('param1');
    param2 varchar2(1000) := param('param2');
    ......
    %>
    <html>
    <head>
    <title>Page</title>
    </head>
    <body>
    <% if param1 is not null and param2 is not null then
    insert into some_table values(param1, param2);
    commit;
    %>Thank you for submitting your data.
    <% else -- parameter missing %>
    Errors in form data:<br>
    <% if param1 is null then %>
    <b style="color:red">Parameter param1 is required.</b><br>
    <% end if; if param2 is null then %>
    <b style="color:red">Parameter param2 is required.</b><br>
    <% end if; %>
    <% exec('my_form'); -- form display object - redisplay the form since some data was invalid.%>
    <% end if; -- main if else %>
    </body>
    </html>

    This example is a form handler that checks input parameters and if some of them are missing (and are required), then it prints a warning and redisplays the form.

    You can download free trial copy of Dynamic PSP at http://www.dpsp-yes.com.
    Victor
    www.dynamicpsp.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width