I am creating a form that requires user confirmation before submitting the data. I would like a seperate confirmation page because I need to display quite a bit information about how the form data will be processed. I was wondering if there was a pythonic way to pass data between forms in Pyramid.
Submitting the form takes the user to the confirmation page. Thus, the view for the confirmation has the form data stored in request.POST. I was wondering if there was a clean way to pass along all of this data to the final view once the user hits 'submit' on the confirmation page. I would also like to add a boolean variable, confirmed, to the dictionary of parameters.
This is not a Pyramid-specific answer, but two common approaches to this problem are:
Store the data in a session.
Store the data as a hidden form on the confirmation page, and resubmit with "confirmed"
I like 2 much better because it's a stateless method. You can also use the exact same form processing logic, and just check for the presence of your "confirmed" POST variable to decide which action to take and view to show (i.e, either the "please confirm" view, or processing and the "processed" view.)
Related
i'm trying to make a user registration with multiple fields to save in the same model. The idea is have a form in the home page with username and password and when press button continue the user is redirected to another page with multiple fields to insert personal info for the user profile.
I imagine i must have two different views for that, but i don't understand how put all this data together.
Thanks!
You could use the FormWizard (https://django-formtools.readthedocs.io/en/latest/wizard.html)
Basically you would have one form for user/password and another form for the other fields.
Take a look
In your case i would prefer manipulate HTML content with JavaScript and after everything is ready, just send an ajax call.
I have a small series of forms. The first accepts two fields, a record ID and an institution ID which need to be passed onto the next form as static information, but needs to be passed together with the rest of the data from the second form which then uses the data from both forms to do the real work. I have marked the first as readonly=true and the other is a select that I am disabling via javascript. When I click "Submit" both return validation errors as missing.
What is the colander approach to do this? I want the values to be visible on the form, so hiddenfield isn't quite right.
I want to know that if i need to perform some search on the job site , then do i need to pass only those variables which are visible on the form or all the variables , even some hidden fields like
The form is here http://www.example.com/search.php
Now there are two fields on the form like searchTerm and area and there are 5 hidden fields
The form submits to http://www.example.com/submit.php
Now i have these doubts
Do i need to open the form page with scrapy with form page url or with the post url
DO i need to pass the hidden variables as well or they will automatically gets posted with the form
if you are using FormRequest.from_response() then all hidden values are already pre-populated automatically.
but in most of the cases you need to override them as well depends on website functionality and behavior.
Sometimes you can go without some of the hidden fields, other times - not.
You cannot know the server logic. It's up to the website how it is handling each of the form fields.
I have a simple Django view that confirms the deletion of an instance. On this page is a simple form containing two buttons, "Cancel" and "Delete."
The Cancel button simply returns the user to the page from which the original delete button was pressed.
The Delete button jumps to a second view that performs the actual action. Thus, my URLs are defined as follows:
url(r'^confirmDeleteItem/(?P<item_key>\w+)$', 'confirm_delete_item'), # Confirms
url(r'^deleteItem/(?P<item_key>\w+)$', 'delete_item'), # Performs the action
On the confirmation page, the form is defined with a POST action that visits the second URL:
<form action="/squash/deleteItem/{{ item.key }}/" method="POST">
...
</form>
The problem I have with this is that the Items are fairly large (they store lots of data) and sensitive, so I'd like to force the user to jump through the confirmation hoop every time.
I would like to either prevent the User from visiting the /deleteItem/ page manually, or just hide the browser's loading of this page to avoid from it becoming stored in the history, accidentally bookmarked, etc.
Is wrapping the action in an AJAX call the best way to solve this problem, or are there more standard/preferred solutions? Thanks!
How about setting a session variable in confirmDeleteItem view (i.e. prepareToDelete = item.key) and checking in deleteItem view whether this session variable exists and whether the value match the item.key? Then you'd just need to remove it after actual delete occurred.
A quick idea which I'm not sure of, but should work in your case.
Check your referer in your deleteItem view. Like in this snippet of code. If user didn't come to the delete view from confirmDelete view, redirect him to the appropriate confirmDelete view.
I've got a web page I'm generating with Pylons and the evoque templating tool. I'm trying to generate a page with multiple forms per page (one form is part of a base template that becomes part of every page). I'm having a problem as I seemingly can only get the form element values for one form; whenever I try to get the value from the base template, I get nothing back. Is there a way in Pylons to get a form element from a form by name? I'm using the request.params("variable_name") style that is standard in Pylons.
Thanks in advance for your help!
Doug
You will only get the form values for the form that was posted in the request(ie: whichever submit button the user clicked), that's how html works.
Yes (to iterate Tom's answer), HTML is designed to explicitly only allow a single form to be submitted at a time. Plus, forms may not be nested, so no confusion possible there.
However, a single form may contain multiple submit buttons. So, you may if you really want to organize your page as one big single form, and so submitting will submit all the values each time. You will need to take care then that there are all field names are distinct -- so, not convenient if you have a repetition of "item" forms, in which case it should be a lot cleaner to have a form per item...