psoares
psoares

Reputation: 4883

how to redirect form after submit

I've a form, where users select the years and gender, then they click on submit. With these values I'm calculating the numbers, drawing some pictures, etc. Everything fine so far.
What I would like to do is open these pictures and data into a pdf file, with the help of documentation.

The thing is that I'm not able to redirect the user when he clicks on the submit button. The code in the template is the following:

<form action="" method="post">
    <div class="report">
         {% for field in form_year %}
             {{ field }}
         {% endfor %}
    </div>
    <div class="report">
        {% for field in form_gender %}
            {{ field }}
        {% endfor %}
    </div>
    {% ifequal id_year None %}{% ifequal id_gend None %}
        <p><input type="submit" value="submit"/>
    {% else %}
        <p><input type="submit" value="submit" onclick="window.open('{% url pdf id_year id_gend %}'),'Ratting','width=700,left=50,height=600,0,status=0,scrollbars=1,');"/></p>
    {% endifequal %}{% endifequal %}

but after selecting some variables, when I click on submit, the input button disappear, and doesn't open any pdf file.
I need the input button to be able to support an hyperlink and he has to be able to save the values the user chose.
Any ideas to solve this?

Thanks

Upvotes: 0

Views: 523

Answers (1)

psoares
psoares

Reputation: 4883

So what I had to do was something like this:

In the view that allow the user to select data:

form_year = YearForm()
form_gender = GenderForm()
return render_to_response('report.html',
                            {
                                'form_year': form_year,
                                'form_gender': form_gender,
                                })

In the view that open the pdf:

if request.method == 'POST':
    form_year = YearForm(request.POST)
    form_gender = GenderForm(request.POST)
    if form_year.is_valid() and form_gender.is_valid():
        id_year = form_year.cleaned_data['years']
        id_gend = form_gender.cleaned_data['gender']
        filename = image #then insert this image into pdf file

and the form, into template:

<form action="./pdf" method="post">
    <div>
         {% for field in form_year %}
             {{ field }}
         {% endfor %}
    </div>
    <div>
        {% for field in form_gender %}
            {{ field }}
        {% endfor %}
    </div>
    <p><input type="submit" value="submit"/></p>
</form>

Upvotes: 1

Related Questions