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 7661501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:36:24+00:00 2026-05-31T13:36:24+00:00

I am building a Form object using pyramid_simpleform. I would like to have one

  • 0

I am building a Form object using pyramid_simpleform. I would like to have one method that builds the form object and once submitted it attempts to validate it.

If the input valid, I’ll redirect the user to a confirmation page. Otherwise, I’ll render an error page. I am using form.validate() to see if the input data fits the schema.

If the form has not been submitted, I’d like to display the form using a render_to_response. How do I detect whether the form has been submitted?

  • 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-31T13:36:25+00:00Added an answer on May 31, 2026 at 1:36 pm

    Quick answer

    Like Furbeenator answered:

    if request.method == "POST":
    

    Long answer

    You should split your logic in two different view functions.

    Also, you should return a form renderer to be used by your template instead of rendering the form straight in the view function. For example:

    ./forms.py:

    from formencode import Schema, validators
    
    class RegistrationForm(Schema):
        email = validators.Email(not_empty=True, strip=True)
        password = validators.UnicodeString(not_empty=True)
        password_confirm = validators.UnicodeString()
        chained_validators = [validators.FieldsMatch(
                        'password', 'password_confirm',
                        messages=dict(invalidNoMatch=u'Password does not match'))]
    

    ./views/accounts.py:

    from pyramid_simpleform import Form
    from pyramid_simpleform.renderers import FormRenderer
    from pyramid.view import view_config
    from pyramid.httpexceptions import HTTPFound
    from pyramid.url import route_url
    from ..forms import RegistrationForm
    from ..models import DBSession, User
    
    @view_config(route_name='accounts_register', renderer='/accounts/register.mako',
                request_method='GET')
    def register(request):
        """Shows the empty form."""
        form = Form(request, schema=RegistrationForm)
        return {'renderer': FormRenderer(form)}
    
    @view_config(route_name='accounts_register', renderer='/accounts/register.mako',
                request_method='POST')
    def register_post(request):
        """Receives the posted form."""
        form = Form(request, schema=RegistrationForm)
        if form.validate():
            user = User(form.data['email'], form.data['password'])
            DBSession.add(user)
            return HTTPFound(route_url('profile', request))
        return {'renderer': FormRenderer(form)}
    

    ./templates/accounts/register.mako:

    <form action="" method="post">
      <div class="${' error' if renderer.is_error('email') else ''}">
        <label for="email">Email</label>
        ${renderer.text('email', type='email', placeholder='Email')}
        % if renderer.is_error('email'):
          <span class="errors">${', '.join(renderer.errors_for('email'))}</span>
        % endif
      </div>    
      <!-- ... --->
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some html that looks like this: <form id=MyUserControl runat=server method=post> <script language=javascript
I'm currently building a web form using APEX that is losely modelled after a
I am building an application using Delphi 7. I have added one button on
I am building a form in Zend Framework 1.9 using subforms as well as
Suppose you're building an HTML form and you want to have 2 or more
I've recently begun working on a project regarding GUI building using some form of
I am building an app using Web2py framework... I don't want to have to
I have a table, say STUDENTS, that is related one-to-many to another table, CLASSES.
I'm building an advanced search form for my ASP.NET MVC app. I have a
I would like to handle the case where a user is editing an object

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.