How about this?
def callback():
mapping=[
('fielda%i','typ_ptyx'),
('fieldb%i','idryma'),
('fieldc%i','sxolh'),
('fieldd%i','titlos'),
('fielde%i','polh_xwra'),
('fieldf%i','etos')]
for i in range(1,100):
values = dict((field,request.vars[key%i]) for key, field in
mapping if request.vars.get(key%i,None))
if not values: break
db.ekped.insert(**values)
On Aug 4, 5:32 am, cogarg <[email protected]> wrote:
> For now, this is the db model:
> db.define_table('ekped',
> Field('userid'), # From db.auth_user.id
> Field('typ_ptyx'),
> Field('idryma'),
> Field('sxolh'),
> Field('titlos'),
> Field('polh_xwra'),
> Field('etos'))
>
> And the form->db field mapping should be like this(N is a number):
> fieldaN -> typ_ptyx
> fieldbN -> idryma
> fieldcN -> sxolh
> fielddN -> titlos
> fieldeN -> polh_xwra
> fieldfN -> etos
>
> Thanks for all the help!
>
> On Aug 4, 12:51 pm, mdipierro <[email protected]> wrote:
>
> > I can send an example. Can you described the model and how input
> > fields should be mapped into db fields?
>
> > On Aug 4, 4:50 am, cogarg <[email protected]> wrote:
>
> > > Thanks for the reply, i will look into replacing the add/remove
> > > functions with that jquery code, but i('ll) still have the same
> > > issue;
> > > I can't figure out how to make a controller that will process the
> > > whole form and insert all the fields in a database.
>
> > > I'm trying to write a loop to manually insert each set of fields to
> > > the database if form.vars.fieldaN is not empty, but i still can't make
> > > it work...
>
> > > On Aug 3, 9:49 pm, mdipierro <[email protected]> wrote:
>
> > > > I suggest you use
> > > > this:http://muiomuio.com/web-design/add-remove-items-with-jquery
>
> > > > and here is a demo:http://muiomuio.com/tutorials/jquery/add-remove/
>
> > > > Massimo
>
> > > > On Aug 3, 1:19 pm, cogarg <[email protected]> wrote:
>
> > > > > Hello,
>
> > > > > I just starting using web2py and i am a little bit lost, since my
> > > > > knowledge of
> > > > > html/css/js/python are mediocre at best.
>
> > > > > What i wanted to create is a form with some standard fields and an
> > > > > option
> > > > > to add more fields(single button, adds 6 fields - an entire db
> > > > > record).
>
> > > > > So far, so good, the html/js portion looks solid, but i can't figure
> > > > > out how to
> > > > > add the extra fields to the database.
>
> > > > > I've used the following js code, which i refined from various
> > > > > examples, which
> > > > > also inserts a number after each and every field name, so the fields i
> > > > > have to
> > > > > work with are named fieldaN , ... , fieldfN .
>
> > > > > <script language="JavaScript">
> > > > > var items=0;
> > > > > function insRow()
> > > > > {
> > > > > items++;
> > > > > var x=document.getElementById('myTable').insertRow(-1);
> > > > > var a=x.insertCell(0);
> > > > > var b=x.insertCell(1);
> > > > > var c=x.insertCell(2);
> > > > > var d=x.insertCell(3);
> > > > > var e=x.insertCell(4);
> > > > > var f=x.insertCell(5);
> > > > > a.innerHTML="<input name=\"fielda" + items + "\" />";
> > > > > b.innerHTML="<input name=\"fieldb" + items + "\" />";
> > > > > c.innerHTML="<input name=\"fieldc" + items + "\" />";
> > > > > d.innerHTML="<input name=\"fieldd" + items + "\" />";
> > > > > e.innerHTML="<input name=\"fielde" + items + "\" />";
> > > > > f.innerHTML="<input name=\"fieldf" + items + "\" />";}
>
> > > > > function delRow() {
> > > > > document.getElementById('myTable').deleteRow(-1)}
>
> > > > > </script>
>
> > > > > I know this is a very bad way to implement this, and i would
> > > > > appreciate any help.