I have a really stupid problem with checkboxes in web2py, i cant get the 
value once a form submit, this is my code:

A javascript modal that show the form

<div class="modal hidden fade in" id="modal-edit-document">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">x</button>
        <h3>Editar pregunta:</h3>
    </div>
    <form action="{{=URL('save_contest_template' , 
args=[selected_contest_id])}}" type="POST" >
        <div class="modal-body">
            {{for q in questions:}}
                <dl>
                    <dt>Orden (lugar dentro del formulario):</dt><dd><input 
placeholder="{{=q['t_order']}}" name="t_order-{{=q['id']}}" type="text" 
class="input-large"/></dd>
                    <dt>Pregunta:</dt>
                    <dd><input id="template_name" 
placeholder="{{=q['name']}}" name="question-{{=q['id']}}" type="text" 
class="input-large" /></dd>
                    <dt>Ayuda:</dt>
                    <dd><textarea rows="3" name="help-{{=q['id']}}" 
placeholder="{{=q['help']}}" ></textarea></dd>
                    <dt>Obligatorio:<input type="checkbox" value='on' 
name="required-{{=q['id']}}" {{if q['is_required']:}} checked{{pass}} 
/></dt>
                    <dt>Mas de un autor:<input type="checkbox" 
name="authors-{{=q['id']}}" {{if q['many_authors']:}} checked{{pass}} 
/></dt>
                    <dt>Mostrar en resumen a usuario:<input type="checkbox" 
name="user_summary-{{=q['id']}}"  {{if q['user_summary']:}} 
checked{{pass}}/></dt>
                    <dt>Mostrar en resumen a administrador:<input 
type="checkbox" name="admin_summary-{{=q['id']}}"  {{if 
q['admin_summary']:}} checked{{pass}}/></dt>
                </dl>      
            {{pass}}
        </div>
        <div class="modal-footer">
            <button  class="btn btn-success" type="submit" >Guardar 
cambios</button>
            <a href="#" class="btn btn-danger" 
data-dismiss="modal">Cerrar</a>
        </div>
    </form>
</div>

And the code to save the info in the database:

@auth.requires_membership('admin')    
def save_contest_template():
    contest_id = request.args[0]
    
    questions_db = 
db(contest_id==db.contest_field.contest).select(db.contest_field.ALL)
    for q in questions_db:       
        var = "question-" + str(q['id'])  
        if request.vars[var] != "":
            q.update_record(name=request.vars[var])
        var = "help-"+ str(q['id'])
        if request.vars[var] != "":
            q.update_record(help=request.vars[var])        
        var = "t_order-"+ str(q['id'])
        if request.vars[var] != "":
            q.update_record(t_order=request.vars[var])
        var = "required-"+ str(q['id']) 
        try:
            if request.vars[var] is not None:
                q.update_record(is_required=True)
        except KeyError ,e:
            q.update_record(is_required=False)
        var = "authors-"+ str(q['id']) 
        try:
            if request.vars[var] is not None:
                q.update_record(many_authors=True)
        except KeyError ,e:
            q.update_record(many_authors=False)
        var = "user_summary-"+ str(q['id']) 
        try:
            if request.vars[var] is not None:
                q.update_record(user_summary=True)
        except KeyError ,e:
            q.update_record(user_summary=False)
        var = "admin_summary-"+ str(q['id']) 
        try:
            if request.vars[var] is not None:
                q.update_record(admin_summary=True)
        except KeyError ,e:
            q.update_record(admin_summary=False)
    redirect(URL('contestedit?contest='+contest_id+'&activeTab=2'))

it works fine for the non checkbox values, but i cant get the checked state 
from checkboxes, i google a litle and find that the checkboxes should have 
value='on' when they are checked, but thats not working for me either

-- 

--- 
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/groups/opt_out.


Reply via email to