Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to an external url with parameters and POST method?

I want save form data before submit to action url in flask

<form action="" method="POST">
    <input type="hidden" name="PAYEE_ACCOUNT" value="U1234567">
    <input type="hidden" name="PAYEE_NAME" value="Name">
    <input type="text"   name="PAYMENT_AMOUNT">
    <input type="submit" name="PAYMENT_METHOD" />
</form>

I can submit this form, but i want save form data before submit

View:

@mod.route('/payment/', methods=['GET', 'POST'])
def payment():
    if request.method != "POST":
        return render_template('form.html')

    form = request.form

    form_data = {'PAYEE_ACCOUNT': form['PAYEE_ACCOUNT'],
                 'PAYEE_NAME': form['PAYEE_Name'],
                 'PAYMENT_AMOUNT' : form['PAYMENT_AMOUNT']
                 }

    # Save Data

    import urllib
    params = urllib.urlencode(form_data)

    url = 'http://www.example.com'
    return redirect(url, params)

Please help me

like image 351
Majid Zandi Avatar asked Jan 10 '23 10:01

Majid Zandi


1 Answers

Sending a 307 status code instead of 302 should tell the browser to preserve the used HTTP method and thus have the behavior you're expecting. Your call to redirect would then look like this:

@mod.route('/payment/', methods=['GET', 'POST'])
def payment():
    if request.method != "POST":
        return render_template('form.html')

    form = request.form

    form_data = {'PAYEE_ACCOUNT': form['PAYEE_ACCOUNT'],
                 'PAYEE_NAME': form['PAYEE_Name'],
                 'PAYMENT_AMOUNT' : form['PAYMENT_AMOUNT']
                 }

    # Save Data

    url = 'http://www.example.com'
    return redirect(url, code=307)
like image 99
hamidfzm Avatar answered Jan 11 '23 23:01

hamidfzm