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

  • SEARCH
  • Home
  • 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 9059177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:54:33+00:00 2026-06-16T14:54:33+00:00

I am new to web programming and this is my first SO question, so

  • 0

I am new to web programming and this is my first SO question, so hopefully I am asking the right way. I am building a simple survey-maker (similar to google forms or survey monkey) and I have a web form that allows the user to add options to a question. Each option has two fields, ‘label’ and ‘value’. The form looks like this:

    Option One
           ------------------           ------------------
    Label: |                |   Value:  |                |
           ------------------           ------------------

    Option Two
           ------------------           ------------------
    Label: |                |   Value:  |                |
           ------------------           ------------------
    ...
    ...
    ... // user can "add option" and additional "rows" will appear in the form

[ SUBMIT ]

I have used a basic web form like this:

<form class="well form" action="/submitform" method="post">
  <p><input type="text" name="label_1">
     <input type="text" name="value_1"></p>
  <p><input type="text" name="label_2">
     <input type="text" name="value_2"></br></p>
  <p>...   // and so forth, to support n sets of two fields
     ...
     ...
  <button type="submit">Submit</button>
</form>

I successfully get request.form and can access each variable in the dict. But of course it’s a single flat dict:

[{'label_1': 'labelone', 'value1': 'valueone', 'label_2': 'label two'}]

and so forth. I want a list of dicts like this:

[ {'label': 'labelone', 'value': 'valueone'}, {'label': 'labeltwo', 'value': 'valuetwo'}]

I’ve thought of several hackish ways to do this, but all require foreknowledge of the number and type of form options. I’d rather find a more flexible solution.

Any best practice here? A lot of sites do things like this so I’m guessing there’s a best practice that I’m missing.

  • 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-06-16T14:54:34+00:00Added an answer on June 16, 2026 at 2:54 pm

    What about this?

    l = [{'label_1': 'labelone', 'value_1': 'valueone', 'label_2': 'label two', 'value_2':'v2'}]
    
    values = int(len(l[0])/2)
    dicts = []
    for i in range(values):
        label_name = 'label_%s' % (i+1)
        value_name = 'value_%s' % (i+1)
        dicts.append({'label':l[0][label_name], 'value':l[0][value_name]})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to web programming in general so this is probably a really simple
I am new to web programming and my first draft of a web page
I am new to web programming...I have been asked to create a simple Internet
First of all, i'm a Graphic designer so please ignore if this programming question
I'm very new to web-application programming with Java. I have two questions. First: I
This is my first time ever touching any sort of client sided web programming
I am new to web programming and Visual Web Developer. I have made a
I am new to web programming,learning VBScript.I want to display few text boxes in
I'm pretty new to web programming, reading a book on ASP.NET, and I notice
I'm new to web programming, so I need some help. I am writing a

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.