Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3434728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:44:02+00:00 2026-05-18T07:44:02+00:00

I put some client-side Javascript in my template that allows a user to dynamically

  • 0

I put some client-side Javascript in my template that allows a user to dynamically add fields to a form. My problem is that these fields are cleaned in form.cleaned_data, so I can’t access them that way.

All the fields are accessible in request.POST, so I could just solve this problem with that, but I want to do this the “right way” and I think that the solution lies somewhere in using django forms rather than reading the request directly.

I tried overriding form.clean(), but it seems like the data is already gone by the time it gets there.

Other details: I am naming these fields fieldname_x, where x is a number. In request.POST, request.POST['fieldname'] is a list of a all the values, but form.cleaned_data contains only the last value of each list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:44:03+00:00Added an answer on May 18, 2026 at 7:44 am

    Do you know what type these fields are going to be beforehand? Are they just going to be simple text fields? I’ve done something similar to this, creating dynamic forms.

    # make sure these exist by examining request.POST
    custom_fields = ['fieldname_1', 'fieldname_2']
    
    attrs = dict((field, forms.CharField(max_length=100, required=False)) 
                 for field in custom_fields)
    DynamicForm = type("DynamicForm", (YourBaseForm,), attrs)
    submitted_form = DynamicForm(request.POST)
    

    Your submitted form should now contain all the fields you require, along with their values. You might want to remove required=False, but that’s up to you.

    What this does, is perform a dynamic subclass of your base form, adding the attributes passed in as attrs to the class definition. So when you create an instance with post data, they should be mapped correctly.

    Edit:

    I read the question a little more closely. What you’ll want to do is ensure that your dynamic input elements are named correctly, and the values map to those fieldnames once it reaches django. Otherwise, request.POST will not fill the form in correctly.

    <input type='text' name='fieldname_1' value='value_for_field_1' /> 
    

    etc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some client-side JavaScript that sets form fields. When the page posts back,
Where do you put user input validation in a web form application? View: JavaScript
I really want to put in some sort of section handler into App.config that
I have about 10million values that I need to put in some type of
I have page that has some javascript that needs to run at page load.
I am using Jquery valdiation plugin for validating the form at client side. I
I need some assistance with some javascript/jquery I have put in place. The function
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I wish to put some text on a page and hide some data in
I want to put some common information in my MasterPage to be shown on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.