1 Reply Latest reply on Mar 18, 2019 10:39 PM by Olafur T

    Migriting from multiple checkboxes with same name

    Olafur T

      Hi,

       

      I already asked this here : Migrating from mod_owa, checkbox input or owa_util.ident_arr value type

       

      But I am now migrating an old system that uses *a lot* of checkboxes in a lot of forms all over, and they all send the same info over i.e. param=1&param=2&param=3.

       

      So, I'm not going to rewrite all those forms to something else. Too plain lazy, Would this function be the correct way to deal with checkboxes in ORDS?

       

      Just wondering of I'm missing something that makes it even simpler

       

      Source type PL/SQL, assuming the checkbox parameter is "t", (could be multiple and then I would do the same with each one)

       

      declare
        l_qs  varchar2(32767) := owa_util.get_cgi_env('QUERY_STRING');
        l_arr apex_t_varchar2;
        l_chk apex_t_varchar2;
        function array_from_form(p_arr in apex_t_varchar2, p_key in varchar2) return apex_t_varchar2 is
          l_ret     apex_t_varchar2 := apex_t_varchar2();
          l_usenext boolean := false;
          l_isval   boolean := false;
        begin
          for i in 1 .. p_arr.count loop
          
            if l_usenext = true and l_isval = true then
              l_ret.extend;
              l_ret(l_ret.count) := p_arr(i);
              l_usenext := false;
            end if;
          
            if p_arr(i) = p_key and l_isval = false then
              l_usenext := true;
            end if;
          
            l_isval := not (l_isval);
          end loop;
        
          return l_ret;
        end;
      begin
        l_arr := apex_string.split(l_qs, '\s*[=&]\s*');
        /* Assuming the checkbox value is "t" */
        l_chk := array_from_form(l_arr, 't');
        /* l_chk has the correct selected values, can work from that */
      
        for i in 1 .. l_chk.count loop
          htp.prn(t(i));
        end loop;
      end;
      

       

      Also, if there is no other way, posting this for other mod_plsql migration experts. lol.

       

      Regards

      Oli

       

      ps. this only works for GET requests, haven't tried yet to work with POST bodies.