> I am having a bit of trouble posting checked items from a form to my > view so I can save it to a database table. > The data in the form are information that has been stripped from a > file so there is no database link/referencing there. > > What I have done half works as it does post my selected items and > saves it to the database but it only posts the last item in the list > rather than the other items I have selected. > > It might just be me looking at this too long or I'm doing something > horribly wrong. > > Any help would be great > > Here is a snippet of my code that I am having problems with.... > > ------Html form--------- > {% for choice in currentproject %} > <form action="/lib/project/{{choice.id}}/" method="POST"> > <table id="searchtable" name="searchtable"> > <tr> > <th>Check Name:</th> > <th>Variable:</th> > <th>Error Message:</th> > <th>Range:</th> > <th>Comments:</th> > <th>Select:</th> > </tr> > > {% if checkstore %} > {% for a,b,c in checkstore %} > <tr> > <td border=1 align="center"><input type="text" > readonly="True" > name="chname" value="{{a}}"/></td> > <td border=1 align="center"><input type="text" > readonly="True" > name="clflag" value="{{b}}"/></td> > <td border=1 align="left"><input type="text" > readonly="True" > name="ermsg" value="{{c}}"/></td> > > <td border=1 align="center"> > <input type="text" name="rangech" value="None"/> > </td> > <td border=1 align="center"> > <input type="text" name="comment" value="None"/> > </td> > <td border=1 align="center"> > <input type="checkbox" name="selectedcheck"/> > </td> > > </tr> > {% endfor %}
This will result in several checkboxes, all with the same value (well, actually, no value at all); how are you going to distinguish between the different checkboxes? Did you check the actualy rendered HTML, and the POST variable you get returned from this form? > > {% endif %} > </table> > <div align="center"> > <br/> > <input type="submit" value="Add to Checks to project"/> > </div> > </form> > {% endfor %} > > -------view------------ > > if request.POST: > selected1 = Project.objects.get(id=project_id) > > try: > selectedch = request.POST['selectedcheck'] You'll only get the last value in this way. See the docs for QueryDict: http://www.djangoproject.com/documentation/request_response/#querydict-objects > > except: > #stops any empty POST errors > qset = (Q(projectid = project_id)) > results = StudyChecksFinal.objects.filter(qset) > return render_to_response('selected.html', { > 'results': results, > 'currentproject': currentproject, > 'theuser' : theuser, > }) > > chname = request.POST['chname'] > clflag = request.POST['clflag'] > ermsg = request.POST['ermsg'] > > try: > range2 = request.POST['rangech'] > except: > range2 = 'None' > try: > comments = request.POST['comment'] > except: > comments = 'None' > if range2 == 'None': > range2 = '' > if comments == 'None': > comments = '' > > new = StudyChecksFinal(projectid=selected1, checkname='%s' %chname, > clinflag='%s' %clflag, errmsg='%s' %ermsg, checkrange='%s' %range2, > comments='%s' %comments) > new.save() --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---