-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Form builder as StreamField block #1564
Comments
+1 |
1 similar comment
👍 |
I'd be very happy to see this implemented. I suppose the big open question is how form submissions can be handled - on the existing form builder, submissions are POSTed to the page's own URL, but an individual StreamField block doesn't have a URL of its own, or anything that can persistently identify it. |
+1! How about setting up a FormBuilder block that, regardless of page it is rendered on, submits to a single site-wide url that takes the PK as a GET param? Much like the URL that page previews rely on, perhaps a unique sequence of symbols that would almost never be replicated would |
I would let the developer decide where the form gets submitted to. In some cases, submitting to the current page itself would be appropriate - if the page has extended the Wagtail form builder base class. In other cases, submitting to a central URL, as in your example; or even a completely different page on a different domain such as a MailChimp subscription could be appropriate. Finally, the form could be AJAXified for completely different behaviour, meaning that it never gets submitted anywhere in particular. If the developer is left to write a template that handles submitting the form, they can write the code that suits their use case very easily: <form action="{{self.url}}" method="post">
{{ self.stream_body }}
<input type="submit">
</form> <form action="/custom-search-page/" method="get">
{{ self.custom_search_form }}
<input type="submit">
</form> <form action="http://email.example.com/subscribe/" method="post">
{{ self.body_with_subscribe_fields }}
<input type="submit">
</form> |
I found myself needing this feature and so I have an implementation. Basically there is a FormFieldBlock that can be added to a StreamField. The page has to inherit from AbstractForm so that form processing happens and it must also include a mixin that pulls the FormFieldBlock "instances" out of the StreamField value to build the form. Submission then happens the same way as a normal AbstractForm. Though the way I have accomplished this may feel a bit hackish. You can see my implementation here: https://github.com/didorothy/wagtail/tree/streamfieldforms Some key files to look at would be:
Template rendering requires a special tag, which I don't really have an example of in the code yet.There is a test case to demonstrate that the tag works but it leaves out several actual details. I'd submit a pull request but it needs more unit tests (I think mainly to prove that form submission and template rendering work) and I need to provide some documentation for how to set things up. I'd like to get some feedback to see if I am on the right track. If I'm headed the right direction I will try to finish up the stuff next week and submit a pull request. |
I was a little later than expected but I have submitted a PR with how I propose that this can be accomplished. I am a bit new to git (though I have used SVN and Mercurial for some time) and I'm not sure I have done everything correctly for a Pull Request. Also, I ran tests with Django 1.9 and Python 3.5 on windows. I may try to set up a VM to do additional testing if needed but I would probably have to do this on another machine as the one I'm using does not have enough RAM to do so effectively. If I need to address anything let me know. |
Just realise i put my comments on a pr and not a thread so: We also required this and have a concept to our requirements. Though very early days or more hours. We have come up with the following. Documentation is currently under way but the highlights are below an maybe useful for ideas:
https://github.com/AccentDesign/wagtailstreamforms Stu |
@stuartaccent Good work! |
cheers @SalahAdDin, not 100% and def needs more work, but is a good starting point for us any road. theres a couple of snaggs like handling validation errors for multiple forms of same type in same page and multiple recaptchas in same page. though not sure if there is a use case for either of these. may help someone else out |
As part of the Wagtail’s first Kickstarter campaign, I’m working on this! |
I’m going to close this in favour of #4485, which seems to be pretty much about the same thing, and covers the most recent changes in this area. |
Is it possible?
The text was updated successfully, but these errors were encountered: