Hi,

this is how I am using the newforms.

My Form

class NewEmployeeForm(forms.Form):

    contract_from = forms.DateField()
    contract_to = forms.DateField()
    position = forms.CharField(max_length=20)

My View

def create_employee(request):
    f = None
    if request.method == 'POST':
        f = NewEmployeeForm(request.POST)
        if f.is_valid():
            return HttpResponse('valid')

    return render_to_response('create_employee.htm', {'form':f})

My Template

<form method="post" action="/manning/create_employee/">
                <p>
                        <label for="id_contract_from">Contract from:</label>
                        <input type="text" name="contract_from" 
id="id_contract_from" />
                        {{form.contract_from.errors}}
                </p>
                <p>
                        <label for="id_contract_to">Contract to:</label>
                        <input type="text" name="contract_to" 
id="id_contract_to" />
                        {{form.contract_to.errors}}
                </p>
                <p>
                        <label for="id_position">Position:</label>
                        <input id="id_position" type="text" name="position" 
maxlength="20" /
>
                        {{form.position.errors}}
                </p>
                <p>
                        <input type="submit" value="Create">
                </p>
                </form>

my problem is after the validation error, I would like to populate the
form with the posted data. One solution is to change my view to

def create_employee(request):
    if request.method == 'GET':
        f = NewEmployeeForm()
    if request.method == 'POST':
        f = NewEmployeeForm(request.POST)
        if f.is_valid():
            return HttpResponse('valid')

    return render_to_response('create_employee.htm', {'form':f})

and my template to
<form method="post" action="/manning/create_employee/">
                <p>
                        {{form.contract_from.label}}
                        {{form.contract_from}}
                        {{form.contract_from.errors}}
                </p>
                <p>
                        {{form.contract_to.label}}
                        {{form.contract_to}}
                        {{form.contract_to.errors}}
                </p>
                <p>
                        {{form.position.label}}
                        {{form.position}}
                        {{form.position.errors}}
                </p>
                <p>
                        <input type="submit" value="Create">
                </p>
                </form>

but my problem here is that how can I apply my css if I can't change
the class attribute of label and input tag generated by the newforms?

any ideas?

james


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to