Massimo, thank you so much.  This solution worked perfectly!

Keep up the great work with web2py.


On Dec 20, 9:01 am, mdipierro <[email protected]> wrote:
> or better
>
> def index():
>     myform=SQLFORM(db.mytest,fields=['studentname'])
>     if myform.accepts(request.vars,session):
>         response.flash='record added'
>     myrecords=db().select(db.mytest.ALL)
>     if request.vars.multiple_update:
>         for r in myrecords:
>             if request.vars.has_key('id%i_grade1' % r.id):
>                 r.update_record(gradeterm1=request.vars['id%i_grade1'
> % r.id],
>                                         gradeterm2=request.vars['id
> %i_grade2' % r.id])
>         myrecords=db().select(db.mytest.ALL)
>     return dict(form=myform, records=myrecords)
>
> and
>
> {{extend 'layout.html'}}
>  <h1>mytest entry form</h1>
>  {{=form}}
>  <h2>Current Records</h2>
>  <form>
> <input type='hidden' name='multiple_update' value="true" />
>  <table>
>  <tr>
>  <td>Student Name</td>
>  <td>Grade - Term1</td>
>  <td>Grade - Term2</td>
>  </tr>
>  {{for record in records:}}
>  <tr>
>     <td>{{=A(record.studentname)}}</td>
>     <td><INPUT type="text", name="id{{=record.id}}_grade1", value=
>  {{=record.gradeterm1}} /></td>
>     <td><INPUT type="text", name="id{{=record.id}}_grade2", value=
>  {{=record.gradeterm2}} /></td>
>  </tr>
>  {{pass}}
>  </table>
> <input type="submit" />
>  </form>
>
> On Dec 20, 1:26 am, mdipierro <[email protected]> wrote:
>
> > In your code.
>
> >  <td><INPUT type="text", name="grade1", value=
> > {{=myrecords.gradeterm1}}></td>
> >    <td><INPUT type="text", name="grade2", value=
> > {{=myrecords.gradeterm2}}></td>
>
> > The two inputs are outside any form therefore nobody receives the
> > input. This is an HTML issue, not a web2py issue. You can try:
>
> > def index():
> >     myform=SQLFORM(db.mytest,fields=['studentname'])
> >     if myform.accepts(request.vars,session):
> >         response.flash='record added'
> >     myrecords=db().select(db.mytest.ALL)
> >     myforms=[SQLFORM(db.mytest,r) for r in myrecords,fields=
> > ['gradeterm1','gradeterm2'])
> >     for f in myforms: f.accepts(request.vars,formname=str
> > (f.records.id))
> >     return dict(form=myform, forms=myforms)
>
> > and
>
> > {{extend 'layout.html'}}
> >  <h1>mytest entry form</h1>
> >  {{=form}}
> >  <h2>Current Records</h2>
> >  <table>
> >  <tr>
> >  <td>Student Name</td>
> >  <td>Grade - Term1</td>
> >  <td>Grade - Term2</td>
> >  <td></td>
> >  </tr>
> >  {{for f in forms:}}
> >  <form>
> >  <tr>
> >     <td>{{=A(f.record.studentname)}}</td>
> >     <td><INPUT type="text", name="gradeterm1", value=
> >  {{=f.latest.gradeterm1}} /></td>
> >     <td><INPUT type="text", name="gradeterm2", value=
> >  {{=f.latest.gradeterm2}} /></td><td><input type="submit" /></td>
> >  </tr>
> >  {{=f.hidden_fields()}}
> >  </form>
> >  {{pass}}
> >  </table>
>
> > On Dec 19, 4:13 pm, fja <[email protected]> wrote:
>
> > > Thanks to everyone for their responses.
>
> > > I am a VB and C# programmer for MS Windows Desktops, so I find myself
> > > at a very steep learning curve here.
>
> > > I have been using web2py for less than a day and am new to programming
> > > with web frameworks.  I like what I have seen so far with web2py and
> > > would like to use the framework for future development.
>
> > > The YUI components do look interesting, however I wouldn't know where
> > > to begin using plugins at this stage.
>
> > > I have included the very simple code I have done so far in hopes that
> > > someone can point me in the right direction towards accomplishing
> > > this.  Articles and/or sample code would be greately appreciated.
>
> > > Following the suggestion from Massimo, I have attempted a solution via
> > > HTML, but I am not sure where to process the request.vars.
>
> > > This is what I have so far....
>
> > > MODEL - db.py
>
> > > db.define_table('mytest', SQLField('studentname', 'string'), SQLField
> > > ('gradeterm1','string'), SQLField('gradeterm2','string'))
>
> > > CONTROLLER - mytest.py
>
> > > def index():
> > >     myform=SQLFORM(db.mytest,fields=['studentname'])
> > >     if myform.accepts(request.vars,session):
> > >         response.flash='record added'
> > >     myrecords=db().select(db.mytest.ALL)
> > >     return dict(form=myform, records=myrecords)
>
> > > VIEW - mytest/index.html
>
> > > {{extend 'layout.html'}}
> > > <h1>mytest entry form</h1>
> > > {{=form}}
> > > <h2>Current Records</h2>
> > > <table>
> > > <tr>
> > > <td>Student Name</td>
> > > <td>Grade - Term1</td>
> > > <td>Grade - Term2</td>
> > > </tr>
> > > {{for myrecords in records:}}
> > > <tr>
> > >    <td>{{=A(myrecords.studentname)}}</td>
> > >    <td><INPUT type="text", name="grade1", value=
> > > {{=myrecords.gradeterm1}}></td>
> > >    <td><INPUT type="text", name="grade2", value=
> > > {{=myrecords.gradeterm2}}></td>
> > > </tr>
> > > {{pass}}
> > > </table>
> > > <INPUT type="submit" value="Save"/>
>
> > > This code gives me a nice form where I can add new students to the db,
> > > and presents me with a list of all students in the db with input boxes
> > > for the 2 term grades for each student.
>
> > > When I press the Save button after filling in the grades, nothing
> > > happens.
>
> > > My questions are
>
> > > 1. Upon pressing Save, who is receiving the data entered for the
> > > grades?
> > > 2. How can I associate the grade entered in the input boxes with the
> > > student in the row, so I can call the update functions to update the
> > > grades for each student respectively.
>
> > > Thank you for help and patience.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to