Form in Tiles with Mosaic

Is that possible to use a z3c form inside a tile?
I've manged to render the form but there is no parameters passed to the request.
It's rendered like that:

class MyTile(Tile):
def index(self):
return queryMultiAdapter((self.context, self.context.REQUEST), name='my_form')()

It seems that somewhere in the process, the request (self.request) has been changed. any idea?

I just had a similar need, this is what I've found out:

plone.app.blocks uses plone.subrequest to retrieve each tile in a "separate" request. The request query is lost during this process, but there's a hope: in your form class (rendered by the tile) you'll have request['PARENT_REQUEST'], which will have the query string.

In my case, I've updated my form class to have something like:

class MyForm(z3c.form.form.Form):
    def __init__(self, context, request):
        super(MyForm, self).__init__(context, request["PARENT_REQUEST"])
    def action(self):
        return self.context.absolute_url()

Seems to work

2 Likes

Thynk you for your reply.
That was maybe somewhere in the docs, but I hadn't found it. At least now it's here!

@tiberiuichim, @MartronicSA I would not recommend poking into request["PARENT_REQUEST"], but would make the form to post to tile URL (or to a named view with the form) and then possibly redirect back to the mosaic view with the form tile. That way form should be processed just normally.

1 Like

@datakurre that means you can't split a form over many tiles I think. It's also limiting to always require a redirect. Is it unreasonable that the request passed into a tile is the same as the page itself?

@djay Yes. By the original design tiles should be independent and retrievable with GET (to support ESI or client-side AJAX fetch).

Of course, for a custom use-case, where you know what you are doing, everything is possible, but it's not recommended by design.