Hi there!

I'm facing troubles with my application. I need to create a dynamic set of 
options (SELECT-OPTION) from a database table. When the user push the 
submit button of a form I need to know what options were selected. I Would 
like to know this from the controller, not from javascript

Part of code in my controller:

    # Get the options from a table (field nombre)
    tipos_de_asunto = 
db2(db2.tipos_de_asunto).select(orderby=db2.tipos_de_asunto.nombre)

    tipos_asuntos_list = []  # I use a list to save the options

   # Looping the resulted set of query 
    for g in tipos_de_asunto:
        #  I Create checkbox
        tipos_asuntos_list += [INPUT(_type="checkbox", 
_name="lista_tipos_asunto", _class="checkbox", _value=g.id, )]
        
        # I create the text of the checkbox
        tipos_asuntos_list += [" " + g.nombre]
        tipos_asuntos_list += [" (" + g.abreviatura + ")"]
        tipos_asuntos_list += [BR()]

        # I create the form (update form)
    form = SQLFORM(db2.auth_user, administrador, submit_button="Aceptar", 
deletable=True, showid=False, formstyle='divs', _id='form_administrador')

    # I create an variable that contains form elements and the options of a 
SELECT (tipos_asuntos_list)
    checkboxes_tipos_asunto = DIV(
                        DIV(
                            LABEL("Tipos Asunto:", 
_for="listado_tipos_asuntos_administradores"),                        
                            _class="w2p_fl"
                        ),
                        DIV(
                            DIV(tipos_asuntos_list, 
_id="listado_tipos_asuntos_administradores"),
                            _class ="w2p_fw"
                        ),
                        DIV(_class ="w2p_fc")
                    )

    # I insert the variable checkboxes_tipos_asunto and the content of list 
tipos_asuntos_list
    form[0].insert(6, checkboxes_tipos_asunto)   # 6 is because I insert 
other form elements, not shown in this code

    if form.validate():
         ?????

    The big question: How I know what options were selected?

    I had thought in use the form.elements with the name of the options, 
but I get all the options without knowing what were selected:

    elementos=form.elements('[name=lista_tipos_asunto]')
    for e in elementos:
         print e

     RESULT OF PRINT:
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="10" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="12" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="9" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="16" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="15" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="17" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="3" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="1" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="4" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="2" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="11" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="6" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="7" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="13" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="14" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" 
value="18" />
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="8" 
/>
<input class="checkbox" name="lista_tipos_asunto" type="checkbox" value="5" 
/>

Any help will be appreciated.

Regards.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to