<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
	<header>
		<title>Form Discovery and Publishing</title>
		<abstract>This specification describes a series of conventions that allow the management of form templates and publishing of completed forms.</abstract>
		
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
		<number>0346</number>
		<status>Deferred</status>
		<type>Standards Track</type>
		<sig>Standards</sig>
		<approver>Council</approver>
		<dependencies>
			<spec>XMPP Core</spec>
			<spec>XEP-0001</spec>
			<spec>XEP-0004</spec>
			<spec>XEP-0030</spec>
			<spec>XEP-0060</spec>
		</dependencies>
		<supersedes/>
		<supersededby/>
		<shortname>NOT_YET_ASSIGNED</shortname>
		
  <author>
    <firstname>Kevin</firstname>
    <surname>Smith</surname>
    <email>kevin.smith@isode.com</email>
    <jid>kevin.smith@isode.com</jid>
  </author>

  <revision>
    <version>0.2</version>
    <date>2017-09-11</date>
    <initials>XEP Editor (jwi)</initials>
    <remark>Defer due to lack of activity.</remark>
  </revision>
		<revision>
		  <version>0.1</version>
		  <date>2014-04-10</date>
		  <initials>editor (mam)</initials>
		  <remark>
		    <p>Initial published version approved by XMPP Council.</p>
		  </remark>
		</revision>
		<revision>
			<version>0.0.1</version>
			<date>2014-04-07</date>
			<initials>ks</initials>
			<remark>
				<p>First draft.</p>
			</remark>
		</revision>
	</header>
	<section1 topic="Introduction" anchor="intro">
		<p>There are many circumstances in which it is necessary for entities to 'fill out forms' to be consumed by other entities (such an example might be for reporting an accident in the workplace). This document provides a method by which an entity can discover which forms are available, fetch the templates and submit the completed forms, using standard XMPP <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note>.</p>
		<p>This is achieved by every form having a pair of pubsub nodes on the same service; one of the nodes contains the template form (the empty form that is to be completed) and the other is used for publishing completed forms.</p>
	</section1>
	<section1 topic="Use Cases" anchor="usecases">
		<section2 topic="Node naming" anchor="naming">
			<p>Pubsub nodes used for these forms are comprised of a standard prefix and an application-specific suffix. Templates and completed forms for the same form type have the same application-specific suffix, but a different prefix. The prefix for form templates is "fdp/template/" and for completed forms is "fdp/submitted/".</p>
			<p>The application-specific suffix must be guaranteed to be unique to the application, so it is suggested to start with a domain under the application author's control; as such if Isode Ltd. were to use this approach for feedback on the Christmas party, a node ID might be formed as "fdp/template/isode.com/christmas-party-feedback/2013" to contain the form template and "fdp/submitted/isode.com/christmas-party-feedback/2013" for the submitted nodes.</p>
		</section2>

		<section2 topic="Listing available templates" anchor="list_templates">
			<p>To find the templates present on a pubsub service, do a disco#items as described in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> section 5.2. Those items that have a node ID that starts with "fdp/template" are form templates.</p>
			<example caption="User discovers available nodes"><![CDATA[
<iq id="34385937-3740-411d-a360-374e9ba73202" to="pubsub.stan.isode.net" type="get">
  <query xmlns="http://jabber.org/protocol/disco#items"/>
</iq>

<iq from='pubsub.stan.isode.net' to='sysop@stan.isode.net/4d67a58b4d16cc1d' type='result' id='34385937-3740-411d-a360-374e9ba73202'>
  <query xmlns='http://jabber.org/protocol/disco#items'>
    <item jid='pubsub.stan.isode.net' node='fdp/submitted/stan.isode.net/accidentreport' name='AccidentReport'/>
    <item jid='pubsub.stan.isode.net' node='fdp/template/stan.isode.net/accidentreport' name='AccidentReport'/>
  </query>
</iq>
]]></example>
			<p>In the above example there is one form available, "stan.isode.net/accidentreport"</p>
		</section2>

		<section2 topic="Fetching a template" anchor="fetch_templates">
			<p>To fetch a template, first identify the node that the template is stored in and then request the last published item for that node, as in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> 6.5.5</p>
			<example caption="User fetches a template"><![CDATA[
<iq id="fb73efb3-356e-43ce-98a3-f76d86132745" to="pubsub.stan.isode.net" type="get">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <items max_items="1" node="fdp/template/stan.isode.net/accidentreport" xmlns="http://jabber.org/protocol/pubsub"/>
  </pubsub>
</iq>

<iq from='pubsub.stan.isode.net' to='sysop@stan.isode.net/4d67a58b4d16cc1d' type='result' id='fb73efb3-356e-43ce-98a3-f76d86132745'>
  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    <items node='fdp/template/stan.isode.net/accidentreport'>
      <item id='version01'>
        <x xmlns='jabber:x:data' type='form'>
          <instructions>Please fill in all fields to complete this accident report.</instructions>
          <title>Accident report form.</title>
          <field type='list-single' label='Place of fall:' var='Place'>
            <option label="Kitchen">
              <value>Kitchen</value>
            </option>
            <option label="Conference Room">
              <value>Conference Room</value>
            </option>
            <option label="Engineering">
              <value>Engineering</value>
            </option>
          </field>
          <field type='text-single' label='Type of injury:' var='Type'>
          </field>
          <field type='boolean' label='Ambulance needed?' var='Ambulance'>
          </field>
        </x>
      </item>
    </items>
  </pubsub>
</iq>
]]></example>
		</section2>

		<section2 topic="Template format" anchor="template_format">
			<p>The format of the template should be a standard <span class="ref"><link url="https://xmpp.org/extensions/xep-0004.html">Data Forms (XEP-0004)</link></span> <note>XEP-0004: Data Forms &lt;<link url="https://xmpp.org/extensions/xep-0004.html">https://xmpp.org/extensions/xep-0004.html</link>&gt;.</note> form; this can be extended with <span class="ref"><link url="https://xmpp.org/extensions/xep-0122.html">Data Forms Validation (XEP-0122)</link></span> <note>XEP-0122: Data Forms Validation &lt;<link url="https://xmpp.org/extensions/xep-0122.html">https://xmpp.org/extensions/xep-0122.html</link>&gt;.</note> and/or <span class="ref"><link url="https://xmpp.org/extensions/xep-0141.html">Data Forms Layout (XEP-0141)</link></span> <note>XEP-0141: Data Forms Layout &lt;<link url="https://xmpp.org/extensions/xep-0141.html">https://xmpp.org/extensions/xep-0141.html</link>&gt;.</note> as needed by individual form applications. The template will be the pubsub item.</p>
		</section2>

		<section2 topic="Submitting a completed form" anchor="submit_form">
			<p>When the form has been completed, the resultant <span class="ref"><link url="https://xmpp.org/extensions/xep-0004.html">Data Forms (XEP-0004)</link></span> <note>XEP-0004: Data Forms &lt;<link url="https://xmpp.org/extensions/xep-0004.html">https://xmpp.org/extensions/xep-0004.html</link>&gt;.</note> payload shall be published to the completed items node corresponding to the form type using the protocol in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> 7.1. The node ID for publishing completed forms corresponds to the node the template was stored in, with the fdp/template prefix replaced with the fdp/submitted prefix.</p>
			<example caption="User submits the completed form"><![CDATA[
<iq id="fc2e69de-4626-47d3-b04b-1cd6b4049b3f" to="pubsub.stan.isode.net" type="set">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <publish node="fdp/submitted/stan.isode.net/accidentreport" xmlns="http://jabber.org/protocol/pubsub">
      <item id="" xmlns="http://jabber.org/protocol/pubsub">
        <x type="submit" xmlns="jabber:x:data">
          <title>Accident report form.</title>
          <field label="Place of fall:" type="list-single" var="Place">
            <value>Kitchen</value>
          </field>
          <field label="Type of injury:" type="text-single" var="Type">
            <value>Ankle</value>
          </field>
          <field label="Ambulance needed?" type="boolean" var="Ambulance">
            <value>1</value>
          </field>
        </x>
      </item>
    </publish>
  </pubsub>
</iq>
]]></example>
		</section2>

		<section2 topic="Monitoring completed form" anchor="monitor_forms">
			<p>An entity can monitor completed forms by subscribing to the completed form node, as described in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> 6.1.</p>
			<example caption="User subscribes to a completed form node"><![CDATA[
<iq id="0f66fbcf-6148-40ed-a084-a3a5e2a71329" to="pubsub.stan.isode.net" type="set">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <subscribe jid="sysop@stan.isode.net/763be9c30f8ee893" node="fdp/submitted/stan.isode.net/accidentreport" xmlns="http://jabber.org/protocol/pubsub"/>
  </pubsub>
</iq>
]]></example>
		</section2>

		<section2 topic="Publishing form templates" anchor="publish_templates">
			<p>Form templates are made available by publishing them to the template node for that form using the protocol in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note> 7.1.</p>
			<example caption="Administrator publishes a form template"><![CDATA[
<iq id="309d632d-fa68-4004-8611-d11cc5074d66" to="pubsub.stan.isode.net" type="set">
  <pubsub xmlns="http://jabber.org/protocol/pubsub">
    <publish node="fdp/template/stan.isode.net/accidentreport">
      <item id="version01">
        <x xmlns="jabber:x:data" type="form">
          <instructions>Please fill in all fields to complete this accident report.</instructions>
          <title>Accident report form.</title>
          <field type="list-single" label="Place of fall:" var="Place">
            <option label="Kitchen">
              <value>Kitchen</value>
            </option>
            <option label="Conference Room">
              <value>Conference Room</value>
            </option>
            <option label="Engineering">
              <value>Engineering</value>
            </option>
          </field>
          <field type="text-single" label="Type of injury:" var="Type">
        </field>
          <field type="boolean" label="Ambulance needed?" var="Ambulance">
        </field>
      </x>
    </item>
  </publish>
</pubsub>
</iq>
]]></example>
		</section2>

		<section2 topic="Node configuration" anchor="node_configuration">
			<p>Template nodes must be configured to support at least one persistent item. Both templates and published nodes need to be configured with appropriate access to publish and subscribe. Deployments may be configured such that entities are allowed to read the templates and submit completed forms, but not to read the completed forms.</p>
		</section2>
	</section1>
	<section1 topic="Determining Support" anchor="support">
		<p>All of the form activity happens over standard pubsub, so initial discovery is of the pubsub domain. A pubsub domain supporting these forms will have an additional disco identity (additional to the standard pubsub identity) with a category of 'pubsub' and a type of 'urn:xmpp:fdp:0'. </p>
    	<example caption="Entity Queries Pubsub Service Regarding Supported Features"><![CDATA[
<iq type='get'
    from='sysop@stan.isode.net/763be9c30f8ee893'
    to='pubsub.stan.isode.net'
    id='feature1'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>]]></example>
    	<example caption="Pubsub Service Includes FDP in its identities"><![CDATA[
<iq type='result'
    from='pubsub.stan.isode.net'
    to='sysop@stan.isode.net/763be9c30f8ee893'
    id='feature1'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <identity category='pubsub' type='service'/>
    <identity category='pubsub' type='urn:xmpp:fdp:0'/>
    <feature var='http://jabber.org/protocol/pubsub'/>
  </query>
</iq>]]></example>
		<p>Discovery of the template forms or completed form nodes happens using the protocol described in <link url="#usecases">Use Cases</link>.
		</p>
	</section1>
<!--	<section1 topic='Implementation Notes' anchor='impl'>

	</section1>-->
	<section1 topic="Security Considerations" anchor="security">
		<p>This document introduces no security considerations beyond those in <span class="ref"><link url="https://xmpp.org/extensions/xep-0060.html">Publish-Subscribe (XEP-0060)</link></span> <note>XEP-0060: Publish-Subscribe &lt;<link url="https://xmpp.org/extensions/xep-0060.html">https://xmpp.org/extensions/xep-0060.html</link>&gt;.</note>.</p>
	</section1>
	<section1 topic="IANA Considerations" anchor="iana">
		<p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
	</section1>
	<section1 topic="XMPP Registrar Considerations" anchor="registrar">
		<p>Include the "urn:xmpp:fdp:0" namespace in the registry of protocol namespaces. Include "urn:xmpp:fdp:0" as an additional type in the pubsub category of service discovery identities.</p>
	</section1>
	<section1 topic="XML Schema" anchor="schema">
		<p>As this document only defines semantics for existing protocol, additional schemas are not required.</p>
	</section1>
	<section1 topic="Acknowledgements" anchor="ack">
		<p>Thanks to Matthew Wild, Richard Maudsley and Alex Clayton.</p>
	</section1>
</xep>
