D
D
django_teapot2015-07-09 19:47:16
Django
django_teapot, 2015-07-09 19:47:16

Django - how to pass parameters to a form?

Hello! Please help me with django. There is a FormView - a contact form for collecting email. How can I pass parameters to it not via URL ? Let me explain, there is an Item model, there is a list of items (ItemListView) - data about the selected item is loaded there via AJAX and information about it is displayed without reloading the page, as well as the "Submit request" button. The button displays the form (FormView) - without binding to the fields of the model. Here's how to make it so that the subject selected by the user is available in the form_valid of this form?
UPD:
Roughly speaking: I need the Item's ID - received using AJAX, to be sent to the FormView (contact form) (maybe I misunderstand and name something, I have a bad idea how it all works), in order to use this ID in the FormView for forming the body of the email, which is the FormView and sends. Oh how =)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2015-07-09
@deliro

Initial data
1) Get pk Item'a (id)
2) Change the Value of Input with JS.
Basically, you're contradicting yourself.

Pass parameters not via URL
and
received with AJAX, send to FormView
. There are several options here. Two correct ones, one curve:
1) Worshiping REST, you make a URL by which you get the form and you will still get a URL like /item/15/getform, where 15 is the pk of your entity
2) Having hammered the REST bolt, you get the form through one URL for everyone entities, passing the required one as a GET parameter. /getform?item=15
3) Forgetting about the rules of decency and REST in general, you make a POST request to the view URL /getformand pass the parameters of the POST request. In this case, they will not be visible in the URL.

S
sim3x, 2015-07-09
@sim3x

stackoverflow.com/questions/7920128/difference-bet...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question