title: Django, validating Form
body: <p>I want my forms to be dynamic, some parameters sucj as max_length for IntegerField varies from model to model. By using the information from <a href="https://stackoverflow.com/questions/622982/django-passing-custom-form-parameters-to-formset/623030#623030">here</a>, I have written this form:</p>
  
  <pre><code>def my_form(inputname, inputlastname, inputamount):
   class MyForm(forms.Form):
    name = forms.CharField(max_length=50,required=True,initial=inputname)
    lastname = forms.CharField(max_length=50, required=True,initial=inputlastname)
    amount= forms.IntegerField(max_value=inputamount, required=True)
   return MyForm
  </code></pre>
  
  <p>It renders well at the template when I call it like this and pass to the template:</p>
  
  <pre><code>form = my_form("David","Bowie",4)()
  </code></pre>
  
  <p>However I can't figure out how can I validate it, this fails:</p>
  
  <p>if request.method == 'POST':
    form = MyForm(request.POST)
    if form.is_valid() </p>