Marlysson, Thanks for the reply. I did figure out how to do it the web2py way. It was not particularly intuitive, but now that I understand it, it makes sense and is pretty powerful.
form=SQLFORM.factory( Field('hostnames',"list:string", default=hostnames,widget=SQLFORM.widgets.checkboxes.widget,requires=[IS_IN_SET(hostnames,multiple=True),IS_NOT_EMPTY()])) form.add_button('Cancel',URL('index')) Then the view just has {{==form}} It works exactly the way I hoped it would. Perhaps an example of this could be put in the examples page. On Saturday, November 26, 2016 at 5:21:59 PM UTC-6, Marlysson Silva wrote: > > I don't used the form.accepted but you could use to validate de submit the > form and handle.. but basically it's > > Em sábado, 26 de novembro de 2016 20:20:58 UTC-3, Marlysson Silva escreveu: >> >> I created a other version for your code, I created a form html ( the hard >> way ) and in the controller get the post vars sent by form: >> >> The controller: >> def form(): >> host_names = ["google","facebook","amazon","localhost"] >> >> marcados = request.post_vars["host"] >> >> return dict(host_names=host_names,marcados=marcados) >> >> The view: >> >> <form method="post"> >> {{for host in host_names:}} >> <label for={{=host}}> {{=host}} </label> >> <input type="checkbox" name="host" value={{=host}} id={{=host}}> >> {{pass}} >> <input type="submit" name="" value="Enviar"> >> </form> >> >> {{=marcados}} >> >> >> Em sábado, 26 de novembro de 2016 02:03:33 UTC-3, Jim Russell escreveu: >>> >>> Hi. >>> >>> I have created a form which takes a list of hostnames and shows the >>> hostnames with checkboxes next to it. The idea is to be able to uncheck any >>> hostnames and pass the still checked hostnames to another function which >>> will then act on that list of hostnames. The problem is that it just >>> returns an empty list. >>> >>> I am new to web2py, this is my first project, so if my thinking is >>> wrong, I'm ok with rewriting this part from scratch. >>> >>> Here is the code: >>> >>> def verify(): >>> hostnames=request.vars.hostnames.split() >>> num_hosts=len(hostnames) >>> form=FORM(TABLE(TR("Hostnames"))) >>> for hn in hostnames: >>> row=XML('<input type="checkbox" name="{{=hn}}" value="{{=hn}}" >>> checked>'+ hn) >>> form[0].append(row) >>> form[0].append(XML('<div >>> id="submit"><button>Submit!</button></div>')) >>> >>> if form.accepts(request,session): >>> redirect(URL('execute',vars=dict(hostnames=form.vars.hostnames))) >>> return dict(hostnames=hostnames,form=form) >>> >>> Thanks in advance for your help. >>> >>> Jim >>> >> -- 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.