Editing a form values

11 views
Skip to first unread message

Nicolas Ardison

unread,
Aug 16, 2012, 2:37:10 PM8/16/12
to django...@googlegroups.com
Hello guys, i can not find how to the following things. 
I have a form that it's not related with any model, and i want to load it with initial data.

##START OF CODE 
class MyForm ( form.Form):
email = forms.CharField(label="Email");
name= forms.CharField(label="name");
lastname =  forms.CharField(label=" lastname");

def Loadname(self,n_name) 
 self.name.value = n_name; # I can not figure out how to do this.
##END OF CODE 

Thanks in advice for your help people!

Nicolas Ardison

Nicolas Ardison

unread,
Aug 16, 2012, 3:08:14 PM8/16/12
to django...@googlegroups.com
I found how to solve it, Dismiss this message, i read in documentation.

##START OF CODE 
class MyForm ( form.Form):
email = forms.CharField(label="Email");
name= forms.CharField(label="name");
lastname =  forms.CharField(label=" lastname");

def Loadname(self,n_name) 
 self.fields[' name '].initial = ' n_name ';
##END OF CODE 

Melvyn Sopacua

unread,
Aug 16, 2012, 5:27:26 PM8/16/12
to django...@googlegroups.com
On 16-8-2012 21:08, Nicolas Ardison wrote:
> I found how to solve it, Dismiss this message, i read in documentation.
>
> ##START OF CODE
> class MyForm ( form.Form):
>
> email = forms.CharField(label="Email");
> name= forms.CharField(label="name");
> lastname = forms.CharField(label=" lastname");
>

<https://docs.djangoproject.com/en/1.4/ref/forms/api/#django.forms.Form.initial>

initial = {
'email': 'y...@example.com',
'name': 'John',
'lastname': 'Doe',
}

form = MyForm(initial=initial)
--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages