Hi, my problem is that the "initial" parameter in forms.Form seems to
have no effect. I set the "subject" value in this code:
form = ContactForm(
initial={'subject': 'I love your site!'}
)
...yet this initialization string never makes it to the HTML as the
default value for the "subject" input field. My question is, why
not? What am I doing wrong?
I am using Django 1.0.2-1 on Kubuntu, python 2.6.2.
The model definition is as follows:
from django import forms
t_char = forms.CharField
t_email = forms.EmailField
class ContactForm(forms.Form):
subject = t_char(max_length=100)
email = t_email(required=False)
message = t_char(widget=forms.Textarea)
The sample views file looks like the following:
from django.shortcuts import render_to_response
from mysite.contact.forms import ContactForm
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
[...]
else:
form = ContactForm(
initial={'subject': 'I love your site!'}
)
return render_to_response('contact_form.html', {'form': form})
The contact_form.html looks like this:
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<h1>Contact Us</h1>
{% if errors %}
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
<form action="/contact/" method="post">
<p>Subject: <input type="text" name="subject"></p>
<p>Your email (optional): <input type="text" name="e-mail""></
p>
<p>Message: <textarea name="message" rows="10" cols="50"></
textarea></p>
<input type="submit" value="Submit">
</form>
</body>
</html>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.