如何在Toad中使用PL / SQL提交HTML表单?

问题描述 投票:0回答:1

我正在尝试使用web工具包从Toad中使用PL / SQL提交数据。我有以下内容

procedure add_car is 
        begin
           htp.title('August Vehicle Directory');
           htp.bodyopen; 
           Htp.tableopen('border=1 align=center');
                   --Header:
                   HTP.tablerowopen;
                        htp.tabledata(style('Add New Vehicle','#t_1'),'center', ccolspan => '5');
                   HTP.tablerowclose;
                   htp.tablerowopen;
                        htp.tabledata(style('Please add a vehicle to the database by filling out the forum below.','#t_msg'),'center',ccolspan=>'11');
                   htp.tablerowclose;

                   -- Text-box entry:
                   htp.tablerowopen; 
                        HTP.P('<td>');
                            htp.tableopen(); 
                            --
                                htp.formopen('john_package.submit_newcar','post');
                                    htp.tablerowopen;
                                    htp.tabledata(style('Make: ','#t_b'),'center');
                                    htp.tabledata('<input type="text" name="make_box" size="20" maxlength="30" value="">');   
                                    htp.tabledata('&nbsp');
                                    htp.tabledata(style('Model: ','#t_b'),'center');
                                    htp.tabledata('<input type="text" name="model_box" size="20" maxlength="30" value="">');
                                    htp.tabledata('&nbsp');
                                    htp.tabledata(style('Year: ','#t_b'),'center');
                                    htp.tabledata('<input type="text" name="year_box" size="20" maxlength="30" value="">'); 
                                    htp.tabledata('&nbsp');
                                    htp.tabledata(style('Engine: ','#t_b'),'center');
                                    htp.tabledata('<input type="text" name="engine_box" size="20" maxlength="30" value="">'); 
                                    htp.tabledata('&nbsp');
                                    htp.tabledata(style('Seats: ','#t_b'),'center');
                                    HTP.P('<td>');  
                                        htp.formSelectOpen('seats_dropdown');
                                        htp.formSelectOption('1');
                                        htp.formSelectOption('2');
                                        htp.formSelectOption('3');
                                        htp.formSelectOption('4');
                                        htp.formSelectOption('5');
                                        htp.formSelectOption('6');
                                        htp.formSelectOption('7');
                                        htp.formSelectOption('8');
                                        htp.formSelectOption('9');
                                        htp.formSelectOption('10');
                                        htp.formSelectClose;
                                    HTP.P('</TD>');
                                    htp.tablerowclose;
                                htp.formclose;
                                --
                            htp.tableclose;
                        HTP.P('</TD>');
                   htp.tablerowclose;   

                   HTP.tablerowopen;
                        HTP.P('<td align =center colspan=2>');
                        htp.tableopen();
                               htp.tabledata(support.button(0,'p_Submit','Add Vehicle','onClick="return this.form"'));
                               htp.tabledata(support.button(0,'john_package.loadpage','Cancel', 1, null, null),'center');
                               htp.tableclose; 
                        HTP.P('</TD>');               
                   HTP.tablerowclose;  

           htp.tableclose;
           htp.bodyclose;
        exception
            when others then
                htp.p('Error: '||TO_CHAR(SQLCODE)||'-'||SQLERRM);
                write_log ('john_package.add_car', to_char(SQLCODE)||'-'||SQLERRM);
        end add_car;

然后我有一个程序,应该从上面提交的表单中插入数据:

        procedure submit_newcar(
            p_make       varchar2 default null,
            p_model        varchar2 default null,
            p_year    varchar2 default null, --Year produced
            p_engine        varchar2 default null, --Engine type
            p_seats        varchar2 default null --Number of seats
            ) IS
        begin
            INSERT INTO JOHN_TABLE_CAR
            (ID, MAKE, MODEL, YEAR, ENGINE, SEATS)
            VALUES 
            (null, p_make, p_model, p_year, p_engine, p_seats);
        exception
            when others then
                htp.p('Error: '||TO_CHAR(SQLCODE)||'-'||SQLERRM);
                write_log ('john_package.submit_newcar', to_char(SQLCODE)||'-'||SQLERRM);
        end submit_newcar;

这似乎不像我预期的那样工作。每次单击“添加车辆”按钮时,似乎都没有调用“submit_newcar”过程中的插入。我怎样才能让它正常工作?

html forms oracle plsql toad
1个回答
0
投票

所以问题的答案非常简单,并且注意到整个检查页面的源HTML。基本上,我没有在表单中包含我的“提交”,因此每次单击提交按钮都没有做任何事情。

要解决这个问题,我需要在表单内移动以下内容

                HTP.P('<td align =center colspan=2>');
                    htp.tableopen();
                           htp.tabledata(support.button(0,'p_Submit','Add Vehicle','onClick="return this.form"'));
                           htp.tabledata(support.button(0,'john_package.loadpage','Cancel', 1, null, null),'center');
                    htp.tableclose; 
                HTP.P('</TD>');
-- /\ submit button is inside form close now!
htp.formclose;

这样做解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.