-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alert for form success #324
Comments
Generally when you submit a form and it is successful you redirect to an alternate page using a 303 when form submission is successful due to how browsers treat POST. |
Generally when you submit a form and it is successful you redirect to an
alternate page using a 303 when form submission is successful due to how
browsers treat POST.
I prefer to stay on the same page as the user is likely to want to use the
form repeatedly in some instances (and the same page also shows data which
has previously been entered). I find it a waste of time to go back and
forth between pages for data entry like tasks.
|
You can redirect to the same page. It switches the browser into GET mode so that when the user refreshes the page it doesn't try to re-submit the previous form data. |
You may want to try using the pyramid "flash" messages. You'd store a "successful" message on the POST and then on the first GET it would display the "flash" message. http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/sessions.html#flash-messages |
I'm not having an issue with GET mode (I handle both POST and GET in the same function anyway, which calls a subfunction to generate the form as necessary). Would be nice if I could indicate success. Right now I'm already using flash messages, but something built-in would be a bit better (using the same template as the warnings which come out when there's a submission problem). |
@ngoonee Thank you for the feedback. In the case you need this functionality often, I suggest you subclass Currently, as most web forms do some sort redirect after success, flash message is the best practice. If one needs themed flash messages please feel free to see examples in https://websauna.org/docs/narrative/misc/messages.html If you want to pursuit this feel free to open a pull request. I'll leave this issue open for now for two months. |
Thanks, since the consensus seems to be that flash messages are more suitable (and I already use them) I'll drop this. |
Currently, if validation fails and we render the ValidationFailure object, the resulting form contains an alert at the top, a clear indication that the something was wrong with the input data.
Would it be possible to have the opposite, a 'success' alert built-in to the form. The exact string being put into the alert could probably be defined as an argument to render, something like
my_form.render(success='<strong>Insert</strong> successful')
I'm currently doing this manually, but that requires me to have additional code both on the python side and the view (template) side for EACH form in my app. Would be nice to bake it in.
The text was updated successfully, but these errors were encountered: