XForms Sending Multiple Instances/Actions

Well, apparently I didn’t look very hard for this solution, because this morning I found a whole list of examples. These are the most useful two that I found:

Turns out it is really simple, and I probably should have figured it out without any examples. Essentially you can use the xforms send action as many times as you like in a single trigger (I should have known this because for I have used multiple inserts in a single trigger before, which is a similar idea).

First in the XForms model:

(:Submit metadata to xquery for processing and updating current record in eXist:)
<xforms:submission id="submitMetadata" method="post" replace="all"
  action="{concat('submitXForm.xql?pid=', $id)}"/>

(:Send solr instance directly to solr:)

<xforms:submission id="submitSolr" method="post" replace="all"
  action="http://localhost/solr/update" ref="instance(solr)"/>

Then in the user interface:

  <xforms:label>Save Both</xforms:label>
  <xforms:action ev:event="DOMActivate">

<xforms:send submission="submitMetadata" />

<xforms:send submission="submitSolr"/>



This posts the metadata instance to an xquery that then updates the record in eXist and simultaneously posts the Solr instance directly to Solr.

I have a few options on how to do this. I could have two instances, one for metadata editing, and one for the Solr indexing. The solr instance would be tied to the data in the first by a series of bind statements and would get updated as the user edits the metadata record.


 <xforms:bind  id="title"


  relevant="string-length(instance('metadata')//dc:title) != 0"/>

I would then need make this submit button conditional, only available when the record is marked as complete. This can be accomplished with a ref=”//dc:status[. = ‘complete’]” attribute on the trigger, or using bind/relevant in the xforms model. This submission would send both instances, one to eXist and one to Solr, as shown above.

The other option would be to have the second submit call an XQuery that creates the Solr index record (in a new XForm). This would require an additional click, for example, when the user saves a completed record there could be a pop-up that asks if the user really wants to “publish” this data, when they click yes this XForm would POST to Solr and close the pop-up window (except I also still need a way to submit the <commit> to Solr). This is the method that I will most likely use. There are a few reasons, one, I already have an XQuery written to create the index records, so it would be faster to put into place. Secondly, when an item has OCR/Transcript, or other full text version, the XQuery will grab that text and submit it to Solr as well. I could probably finagle this into my main XForm but I’m not sure it is worth the effort as I don’t need to pull in the full text for metadata editing. I also like the idea of keeping my two forms separate so that as/if I add Solr fields I will not need to tinker with the main metadata form.


One Response to “XForms Sending Multiple Instances/Actions”

  1. Solr/XForms Continued « the DIL Says:

    […] the DIL One ‘l’ short of a savory little herb. A Digital Initiative Librarian’s blog. « XForms Sending Multiple Instances/Actions […]

Comments are closed.

%d bloggers like this: