two forms submitted into the same cotroller

93 views
Skip to first unread message

Andrey K

unread,
Aug 29, 2014, 5:10:59 PM8/29/14
to web...@googlegroups.com
Dear list,

I have two related questions:

1. Basically I have one view (C) which contains two forms A and B. The dynamic form A is created by controller A and added by web2py_component (Ajax call). The static  form B is created by controller B and added via helper LOAD. I want to submit both forms into controller A of form A. How to do it ?

2. Also I want to know how I can have one controller that will dynamically create  two forms via web2py_component (Ajax call) and place both of them into the two separate div's of the same view. I want then that the data of both forms are submitted simultaneously into the same controller and processed there?

I managed to generate two forms in one controller but I cannot separate them into different div's on the same view.

I would be happy if you could advise me on this,
Andrey

Massimo Di Pierro

unread,
Aug 29, 2014, 7:36:33 PM8/29/14
to web...@googlegroups.com
Something is wrong here. Can you explain at higher level what are you trying to achieve?

Andrey K

unread,
Aug 30, 2014, 4:24:16 PM8/30/14
to web...@googlegroups.com
Hi Massimo,
Here is my dilemma:
I have one view with 3 tabs (DIVS), where I would like to have one tab for user tool selection and two forms in 2 separated tabs(DIVs) : 1)static form and 2)dynamic form(generated based on user selection in first tab). Also I would like to submit all information from both forms into only one controller as two separated peaces of data, where I can nicely parse it and store in one record of the db.table, so it would be nice to have only one button to trigger it.
I have tried many ways but it did not work exactly the way I need it: either I can't present two forms in separated view divs or I can't submit both to only one controller. The last approach I had that did it almost the thing was to use HTML5 _form attribute for all form elements and button and related form _id attribute. But I have trouble submitting data back to the controller that generate my dynamic form, added to DIV via web2py_ajax_component.
Please help me out. What would be the way to make it in w2p?

Massimo Di Pierro

unread,
Aug 30, 2014, 8:31:17 PM8/30/14
to web...@googlegroups.com
I believe your problem is the XY problem. http://mywiki.wooledge.org/XyProblem
Y = "submitting to forms to the same controller".
Do no ask about Y. What it your original problem X for which you think Y is a good solution?

Andrey K

unread,
Aug 31, 2014, 3:45:02 PM8/31/14
to web...@googlegroups.com
Thanks Massimo.
Here is my reformatted question(hope it will be more understandable):
I want to present two input sets of information coming from server into two sections of the same view (div1 and div2). First input set is generated based on user choice control, that presented at the same view(div 0), the second is user based.
How to
1)organize data fetching/adding INPUT sets to the view so
2)all user input can be submitted back to the server from these two input data sets into one data table record, icluding user selection choice.

Here is how it looks in the result view and DB recorde:

View:

<tab0>

<div id=0> SELECT(t1,t2,t3)</div>

</tab0>

<HTML CODE>

<tab1>

<div id=1>

INPUT(_name=’file’, _value=’’, default = 0)

INPUT(_name=’parameter’, _value= , default=100)

</div>

</tab1>

<HTML CODE>

<tab2>

<div id2>

INPUT(_name=purpose, _value=’processing’)

</div>

<tab2/>

<HTML CODE>

Db.table row result:

User_choice, file, parameter, purpose

t1 , 0 , 100, ‘processing’


Thank you in advance.
Please let me know if you need more details.

Massimo Di Pierro

unread,
Aug 31, 2014, 5:18:49 PM8/31/14
to web...@googlegroups.com
This helps but I still have some questions... where is <form>? what is <tab1>? is this used the output of two generated SQLFORM? or the actual source view?

Cliff Kachinske

unread,
Sep 2, 2014, 6:08:06 PM9/2/14
to web...@googlegroups.com
Here is what I do.

Your page should have one form only.

Make 2 divs. Top div has your fixed fields including the one that triggers the variable content.

Use jquery to catch the change event for the field. When the field changes send an Ajax request to the server.

Let the server build the variable form and return it to the server to populate the second div.

I build the individual form elements rather than using FORM or SQLFORM. That way I avoid form within a form problems.

Andrey Khmelevskiy

unread,
Sep 10, 2014, 8:27:07 AM9/10/14
to web...@googlegroups.com

Thank Cliff and Massimo for your help.
I have finally make in very similar fission:
I have 2 divs,
controller1 with static form with id=1 that inserted in div1,
another controller2 that triggers by w2p_component (ajax) and generates form with id=2 and inserted to div2 but all input fields of this form has HTML 5 attribute "_form=1",
Plus I have button with the same "_form=1"

So when I submit/click the button -both forms submitted vars get to the  controller1 and inserted to the same record of my db table.

It works well for me.

This approach did not work when I insert my forms from controller1 via LOAD helper

Regards

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/jNsHXtD0VqI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages