Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango multiple forms and keep field data input after submission
    text
    copied!<p>I'm new to Django and I have a page with several forms and submit buttons. How can I store the data on the fields of the other forms if one is submitted? Normally when I submit one, it redirects to the same page but if something was typed on the fields is lost. Thanks.</p> <p>This is the Html</p> <pre><code>&lt;head&gt; &lt;title&gt;Hello&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}/static/tabs.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Informacion&lt;/h1&gt; &lt;ol id="toc"&gt; &lt;li&gt;&lt;a href="#page-1"&gt;&lt;span&gt;Page 1&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#page-2"&gt;&lt;span&gt;Page 2&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#page-3"&gt;&lt;span&gt;Page 3&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#page-4"&gt;&lt;span&gt;Page 4&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; &lt;div class="content" id="page-1"&gt; &lt;h2&gt;Page 1&lt;/h2&gt; &lt;p&gt;Text...&lt;/p&gt; &lt;form action="." method="POST"&gt;{% csrf_token %} &lt;table&gt; {{ form1.as_table }} &lt;/table&gt; &lt;p&gt;&lt;input type="submit" value="Submit"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;div class="content" id="page-2"&gt; &lt;h2&gt;Page 2&lt;/h2&gt; &lt;p&gt;Text...&lt;/p&gt; &lt;form action="." method="POST"&gt;{% csrf_token %} &lt;table&gt; &lt;/table&gt; &lt;p&gt;&lt;input type="submit" value="Submit"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;div class="content" id="page-3"&gt; &lt;h2&gt;Page 3&lt;/h2&gt; &lt;p&gt;Text...&lt;/p&gt; &lt;form action="." method="POST"&gt;{% csrf_token %} &lt;table&gt; {{ form2.as_table}} &lt;/table&gt; &lt;p&gt;&lt;input type="submit" value="Submit"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;div class="content" id="page-4"&gt; &lt;h2&gt;Busqueda&lt;/h2&gt; &lt;form action="." method="POST"&gt;{% csrf_token %} &lt;table&gt; {{ form2.as_table}} &lt;/table&gt; &lt;p&gt;&lt;input type="submit" value="S"&gt;&lt;/p&gt; &lt;/div&gt; &lt;script src="{{ MEDIA_URL}}/static/activatables.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; activatables('page', ['page-1', 'page-2', 'page-3','page-4']); &lt;/script&gt; &lt;/body&gt; </code></pre> <p>Well, there are some tabs made in java script for each different form, so what I want to do is that when you submitt data for one form, the other data in the fields of the rest of the forms should be kept, so the user shouldnt type it again or lose it. Thanks in advance.</p> <p>in the view...</p> <pre><code>if request.method == 'GET': form1 = HcGinecoForm() form2 = HolaForm() else: form1 = HcGinecoForm(request.POST) form2 = HolaForm(request.POST) if form1.is_valid and form2.is_valid(): form1.save() form2.save() return render_to_response('polls/hola.html',{ 'form2':form2, 'form1':form1 }) </code></pre> <p>It's working so far... thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload