I am implementing a stripe charge in my django ecommerce project. So In my views, I am trying to get the data from an input element in a form, then pass into a variable in the views.
Here is the Javascript that creates the input element
var form = document.getElementById('stripe-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit()
So in the views.py, I have this:
token = form.cleaned_data.get('stripeToken')
save = form.cleaned_data.get('save')
use_default = form.cleaned_data.get('use_default')
print(form.cleaned_data)
the print(form.cleaned_data) returned a dictionary
{'stripetoken':'', 'save': False, 'as_default': False}
stripetoken maps to the token variable, and as you can see its value is empty. The last two variables that maps to the last two keys in the dictionary returned values.
The token = form.cleaned_data.get('stripeToken') is supposed to get this hiddenInput.setAttribute('value', token.id); right?
When I tried getting the value of token.id, I got a response. I used Javascript alert(token.id) to do that, and I got a value displayed in my browser. So I don't know what exactly is wrong.
Can someone help me out on this one?