meknajirta
meknajirta

Reputation: 65

Django Forms.py Change EmailField Value To Auto Populated value="{{ user.email }}"

I want my Django form's EmailField to auto populate with the user's email. How does this get accomplished? I am not using models.py with this form.

Full Code: https://dpaste.org/4PrR

Instead of 'value':'hi' I want 'value':{{ user.email }}

Code from forms.py:

payment_email = forms.EmailField(widget=forms.TextInput(attrs={'class':'form-control', 'autocomplete':'off', 'type':'email', 'id':'email', 'value':'hi', 'readonly':'readonly'}), required=True)

def __init__(self, *args, **kwargs):
        super(PaymentForm, self).__init__(*args, **kwargs)
        self.fields['payment_email'].label = "Email:"

Upvotes: 0

Views: 156

Answers (1)

schillingt
schillingt

Reputation: 13731

Use the initial parameter when instantiating your form.

form = PaymentForm(data, initial={'payment_email': user.email})

Upvotes: 1

Related Questions