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
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With