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

How to submit an HTML form using PL/SQL in Toad?

我正在尝试通过网络工具包在 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;

这似乎没有按我预期的方式工作。每次我单击 "Add Vehicle" 按钮时,似乎都没有调用 "submit_newcar" 过程中的插入。我怎样才能让它正常工作?

所以问题的答案非常简单,并且在整个检查页面源代码时都注意到了 HTML。基本上,我没有在表单中包含我的 "Submit" 因此每次单击提交按钮都没有任何作用。

为了解决这个问题,我需要将以下内容移到表单中 close

                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;

这样做解决了我的问题。