title: ajax form is_valid returns false (django)
body: <p>I cannot figure out why my form is returning false to is_valid</p>
  
  <p>i have a page called account that has an ajax function to submit a form</p>
  
  <p>i pass my form in on my account view and my createform view</p>
  
  <p>createform view: this is where my ajax is handled</p>
  
  <pre><code>def createrecipe(request):
      print "entering createrecipeview"
      if request.method == 'POST':
          print "form is a post"
          form = RecipeForm(request.POST)
          print form.errors
          if form.is_valid():
              print "form is valid"
              form = RecipeForm(initial = {'original_cookbook' : request.user.cookbooks.all()[0]})
              form = form.save()
              if form.cleaned_data['reset_recipe'] == "True":
                  print "reset recipe"
                  form = RecipeForm(initial = {"original_cookbook": request.user.cookbooks.all()[0]})
                  t = loader.get_template('cookbook/create_form.html')
                  c = RequestContext(request, {
                  'form': form,
                  })
  
                  data = {
                  'replace': True,
                  'form': t.render(c),
                  'success': False,
                  }
  
                  json = simplejson.dumps(data)
                  return HttpResponse(json,mimetype='text/plain')
              t = loader.get_template('cookbook/create_form.html')
              c = RequestContext(request, {
              'form': form,
              })
  
              data = {
              'replace': True,
              'form': t.render(c),
              'success': True,
              }
  
              json = simplejson.dumps(data)
              return HttpResponse(json, mimetype='text/plain')
          else:
              print "form is invalid"
              form = RecipeForm(request.POST)
              t = loader.get_template('cookbook/create_form.html')
              c = RequestContext(request, {
                  'form':form,
              })
  
              data ={
                  'form': t.render(c),
                  'success': False,
              }
  
              json = simplejson.dumps(data)
              return HttpResponse(json, mimetype='text/plain')
  </code></pre>
  
  <p>account view: this is where i pass in the form for the ajax view</p>
  
  <pre><code>def account(request):
      user = request.user
      if request.user.is_authenticated():
          cookbooks = user.cookbooks
          if cookbooks.all().exists():
              cookbook = cookbooks.all()[0]
              form = RecipeForm(request.POST)
              recipe_list = cookbook.recipes.all()
          else:
              raise Http404
      else:
          return HttpResponseRedirect('/accounts/login')
      t = loader.get_template('cookbook/account.html')
      c = RequestContext(request, {
          'form': form,
          'recipe_list': recipe_list
      })
      return HttpResponse(t.render(c))
  </code></pre>
  
  <p>so my question is when when using ajax with django what view do i need to pass the form in on 
  the page that has the ajax js or the page that has the form on it</p>
  
  <p>sorry if this is confusing - if it doesn't make sense please tell me and i will elaborate</p>
  
  <p>here is my form.errors print</p>
  
  <pre><code>&lt;ul class="errorlist"&gt;&lt;li&gt;name&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;ingredients&lt;ul class="errorlist"&gt;&lt;li&gt;This field cannot be null.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;author&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;steps&lt;ul class="errorlist"&gt;&lt;li&gt;This field cannot be null.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;prep_time&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;type&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>this actually makes sense since i am not adding any input to the form it is not validating </p>
  
  <p>sorry but i believe this was a false alarm</p>
  
  <p>here is my js </p>
  
  <pre><code>&lt;script type="text/javascript"&gt; 
  $(document).ready(function(){
      var form = $('form#createrecipeform');
      form.submit(function(e) {
      e.preventDefault();
      console.log('ajax form submission function called successfully.');
      form = $(this);
      console.log(form)
      var serialized_form = form.serialize();
          $.ajax({ type: "POST", 
              url: $(this).attr('action'),
              data: serialized_form, 
              success: (function(data) { 
                  console.log('ajax success function called successfully.');
                  data = $.parseJSON(data);
                  if (data.success) {
                      console.log('success');//i dont know what to do here
                      var newForm = data.form;
                      form.replaceWith(newForm);
                  } else {
                      console.log('failure');// i also don't know what to do here
                      var newForm = data.form;
                      form.replaceWith(newForm);  
                  }
              })
          });
          return false;
      });
  });
  &lt;/script&gt; 
  </code></pre>
  
  <p>katie</p>