Skip to content
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

Closed
ngoonee opened this issue Nov 30, 2016 · 7 comments
Closed

Alert for form success #324

ngoonee opened this issue Nov 30, 2016 · 7 comments
Labels

Comments

@ngoonee
Copy link

ngoonee commented Nov 30, 2016

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.

@digitalresistor
Copy link
Member

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.

@ngoonee
Copy link
Author

ngoonee commented Nov 30, 2016 via email

@mmerickel
Copy link
Member

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.

@tisdall
Copy link
Contributor

tisdall commented Nov 30, 2016

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

@ngoonee
Copy link
Author

ngoonee commented Dec 6, 2016

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).

@miohtama
Copy link
Contributor

miohtama commented Dec 6, 2016

@ngoonee Thank you for the feedback. In the case you need this functionality often, I suggest you subclass deform.form.Form class and build your specific success functionality in there. If you find an elegant solution to do this we can also add this as an example to deformdemo package.

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.

@ngoonee
Copy link
Author

ngoonee commented Dec 14, 2016

Thanks, since the consensus seems to be that flash messages are more suitable (and I already use them) I'll drop this.

@ngoonee ngoonee closed this as completed Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants