https://wiki.mahara.org/index.php?title=Developer_Area/Core_Subsystems/Form_API_(Pieforms)/Form_APIAJAXForms&feed=atom&action=history
Developer Area/Core Subsystems/Form API (Pieforms)/Form APIAJAXForms - Revision history
2024-03-28T10:21:59Z
Revision history for this page on the wiki
MediaWiki 1.35.10
https://wiki.mahara.org/index.php?title=Developer_Area/Core_Subsystems/Form_API_(Pieforms)/Form_APIAJAXForms&diff=1336&oldid=prev
Dirkca at 00:21, 17 May 2011
2011-05-17T00:21:32Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:21, 17 May 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l25" >Line 25:</td>
<td colspan="2" class="diff-lineno">Line 25:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></div></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></div></div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>[[<del class="diffchange diffchange-inline">Catergory</del>:Developer Area]]</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>[[<ins class="diffchange diffchange-inline">Category</ins>:Developer Area]]</div></td></tr>
</table>
Dirkca
https://wiki.mahara.org/index.php?title=Developer_Area/Core_Subsystems/Form_API_(Pieforms)/Form_APIAJAXForms&diff=1335&oldid=prev
Dirkca at 00:21, 17 May 2011
2011-05-17T00:21:21Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:21, 17 May 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l25" >Line 25:</td>
<td colspan="2" class="diff-lineno">Line 25:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></div></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></div></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Catergory:Developer Area]]</ins></div></td></tr>
</table>
Dirkca
https://wiki.mahara.org/index.php?title=Developer_Area/Core_Subsystems/Form_API_(Pieforms)/Form_APIAJAXForms&diff=496&oldid=prev
WikiSysop at 03:13, 11 May 2011
2011-05-11T03:13:11Z
<p></p>
<table class="diff diff-contentalign-left diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en-GB">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 03:13, 11 May 2011</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><div class="toolbar"><br /> The form API supports submission of forms to a hidden iframe (not really AJAX but as I'm writing new documentation elsewhere I can't be bothered renaming this page), just by toggling a single field and changing the 'formname_submit' function to output JSON instead of redirect the user. This makes forms very responsive.</div><div id="section_1"></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><div class="toolbar"><br /> The form API supports submission of forms to a hidden iframe (not really AJAX but as I'm writing new documentation elsewhere I can't be bothered renaming this page), just by toggling a single field and changing the 'formname_submit' function to output JSON instead of redirect the user. This makes forms very responsive.</div><div id="section_1"></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>=== Form submission using JS ===</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===Form submission using JS===</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you want the form to be submitted to the server without a page reload, then all you need to do is set 'jsform' to true, and make sure your formname_submit function echos JSON and exits, as in this example:</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you want the form to be submitted to the server without a page reload, then all you need to do is set 'jsform' to true, and make sure your formname_submit function echos JSON and exits, as in this example:</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><div class="plugin tightenable"><code><font color="#000000"> <font color="#0000bb">$f </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>= array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'name' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'editsitepage'</font><font color="#007700">,<br /> </font><font color="#dd0000">'method' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'post'</font><font color="#007700">,<br /> </font><font color="#dd0000">'jsform' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">true</font><font color="#007700">,<br /> </font><font color="#dd0000">'jssuccessfunction' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'contentSaved'</font><font color="#007700">,<br /> </font><font color="#dd0000">'action' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'elements' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'pagename' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'type' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'text'</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagename'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> ),<br /> </font><font color="#dd0000">'pagetext' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'name' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'pagetext'</font><font color="#007700">,<br /> </font><font color="#dd0000">'type' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'textarea'</font><font color="#007700">,<br /> </font><font color="#dd0000">'rows' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">20</font><font color="#007700">,<br /> </font><font color="#dd0000">'cols' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">80</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagetext'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'rules' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'required' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">true<br /> </font><font color="#007700">)<br /> ),<br /> </font><font color="#dd0000">'submit' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; array(<del class="diffchange diffchange-inline"></nowiki></del><br /> </font><font color="#dd0000">'value' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'savechanges'</font><font color="#007700">),<br /> </font><font color="#dd0000">'type' </font><font color="#007700"<del class="diffchange diffchange-inline">><nowiki</del>>=&gt; <del class="diffchange diffchange-inline"></nowiki></del></font><font color="#dd0000">'submit'</font><font color="#007700">,<br /> )<br /> )<br /> );<br /></font> </font> </code></div></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><div class="plugin tightenable"><code><font color="#000000"> <font color="#0000bb">$f </font><font color="#007700">= array(<br /> </font><font color="#dd0000">'name' </font><font color="#007700">=&gt; </font><font color="#dd0000">'editsitepage'</font><font color="#007700">,<br /> </font><font color="#dd0000">'method' </font><font color="#007700">=&gt; </font><font color="#dd0000">'post'</font><font color="#007700">,<br /> </font><font color="#dd0000">'jsform' </font><font color="#007700">=&gt; </font><font color="#0000bb">true</font><font color="#007700">,<br /> </font><font color="#dd0000">'jssuccessfunction' </font><font color="#007700">=&gt; </font><font color="#dd0000">'contentSaved'</font><font color="#007700">,<br /> </font><font color="#dd0000">'action' </font><font color="#007700">=&gt; </font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'elements' </font><font color="#007700">=&gt; array(<br /> </font><font color="#dd0000">'pagename' </font><font color="#007700">=&gt; array(<br /> </font><font color="#dd0000">'type' </font><font color="#007700">=&gt; </font><font color="#dd0000">'text'</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700">=&gt; </font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagename'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700">=&gt; </font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> ),<br /> </font><font color="#dd0000">'pagetext' </font><font color="#007700">=&gt; array(<br /> </font><font color="#dd0000">'name' </font><font color="#007700">=&gt; </font><font color="#dd0000">'pagetext'</font><font color="#007700">,<br /> </font><font color="#dd0000">'type' </font><font color="#007700">=&gt; </font><font color="#dd0000">'textarea'</font><font color="#007700">,<br /> </font><font color="#dd0000">'rows' </font><font color="#007700">=&gt; </font><font color="#0000bb">20</font><font color="#007700">,<br /> </font><font color="#dd0000">'cols' </font><font color="#007700">=&gt; </font><font color="#0000bb">80</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700">=&gt; </font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagetext'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700">=&gt; </font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'rules' </font><font color="#007700">=&gt; array(<br /> </font><font color="#dd0000">'required' </font><font color="#007700">=&gt; </font><font color="#0000bb">true<br /> </font><font color="#007700">)<br /> ),<br /> </font><font color="#dd0000">'submit' </font><font color="#007700">=&gt; array(<br /> </font><font color="#dd0000">'value' </font><font color="#007700">=&gt; </font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'savechanges'</font><font color="#007700">),<br /> </font><font color="#dd0000">'type' </font><font color="#007700">=&gt; </font><font color="#dd0000">'submit'</font><font color="#007700">,<br /> )<br /> )<br /> );<br /></font> </font> </code></div></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>With jsform set to true, the form handler will create a javascript function that posts the form content to the 'action' target. Normally, you can just leave 'action' blank, as this will submit the data to the page where the form is defined.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>With jsform set to true, the form handler will create a javascript function that posts the form content to the 'action' target. Normally, you can just leave 'action' blank, as this will submit the data to the page where the form is defined.</div></td></tr>
</table>
WikiSysop
https://wiki.mahara.org/index.php?title=Developer_Area/Core_Subsystems/Form_API_(Pieforms)/Form_APIAJAXForms&diff=28&oldid=prev
Brettwilkins: Created page with "<div class="toolbar"><br /> The form API supports submission of forms to a hidden iframe (not really AJAX but as I'm writing new documentation elsewhere I can't be bothered renam…"
2011-05-09T05:55:30Z
<p>Created page with "<div class="toolbar"><br /> The form API supports submission of forms to a hidden iframe (not really AJAX but as I'm writing new documentation elsewhere I can't be bothered renam…"</p>
<p><b>New page</b></p><div><div class="toolbar"><br /> The form API supports submission of forms to a hidden iframe (not really AJAX but as I'm writing new documentation elsewhere I can't be bothered renaming this page), just by toggling a single field and changing the 'formname_submit' function to output JSON instead of redirect the user. This makes forms very responsive.</div><div id="section_1"><br />
<br />
=== Form submission using JS ===<br />
<br />
If you want the form to be submitted to the server without a page reload, then all you need to do is set 'jsform' to true, and make sure your formname_submit function echos JSON and exits, as in this example:<br />
<br />
<div class="plugin tightenable"><code><font color="#000000"> <font color="#0000bb">$f </font><font color="#007700"><nowiki>= array(</nowiki><br /> </font><font color="#dd0000">'name' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'editsitepage'</font><font color="#007700">,<br /> </font><font color="#dd0000">'method' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'post'</font><font color="#007700">,<br /> </font><font color="#dd0000">'jsform' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">true</font><font color="#007700">,<br /> </font><font color="#dd0000">'jssuccessfunction' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'contentSaved'</font><font color="#007700">,<br /> </font><font color="#dd0000">'action' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'elements' </font><font color="#007700"><nowiki>=&gt; array(</nowiki><br /> </font><font color="#dd0000">'pagename' </font><font color="#007700"><nowiki>=&gt; array(</nowiki><br /> </font><font color="#dd0000">'type' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'text'</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagename'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> ),<br /> </font><font color="#dd0000">'pagetext' </font><font color="#007700"><nowiki>=&gt; array(</nowiki><br /> </font><font color="#dd0000">'name' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'pagetext'</font><font color="#007700">,<br /> </font><font color="#dd0000">'type' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'textarea'</font><font color="#007700">,<br /> </font><font color="#dd0000">'rows' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">20</font><font color="#007700">,<br /> </font><font color="#dd0000">'cols' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">80</font><font color="#007700">,<br /> </font><font color="#dd0000">'title' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'pagetext'</font><font color="#007700">),<br /> </font><font color="#dd0000">'value' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000"><nowiki>''</nowiki></font><font color="#007700">,<br /> </font><font color="#dd0000">'rules' </font><font color="#007700"><nowiki>=&gt; array(</nowiki><br /> </font><font color="#dd0000">'required' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">true<br /> </font><font color="#007700">)<br /> ),<br /> </font><font color="#dd0000">'submit' </font><font color="#007700"><nowiki>=&gt; array(</nowiki><br /> </font><font color="#dd0000">'value' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'savechanges'</font><font color="#007700">),<br /> </font><font color="#dd0000">'type' </font><font color="#007700"><nowiki>=&gt; </nowiki></font><font color="#dd0000">'submit'</font><font color="#007700">,<br /> )<br /> )<br /> );<br /></font> </font> </code></div><br />
<br />
With jsform set to true, the form handler will create a javascript function that posts the form content to the 'action' target. Normally, you can just leave 'action' blank, as this will submit the data to the page where the form is defined.<br />
<br />
; The formname_submit function is expected to process the request as normal, and then output JSON to describe the result. The format of this JSON is subject to change, however at the moment it is an array with the following fields<br />
: :* an 'error' field set to either<br />
:** false, if there are no errors, or<br />
:** 'local', if the error is local to this callback, or<br />
:** some other machine readable code for potentially global errors; and<br />
:* a 'message' field set to an appropriate message.<br />
<br />
'local' error messages will be displayed near the form's submit button (as decided by the renderer). Other errors are passed to the global error handler defined in mahara.js. (todo: this may not be implemented at this time - bug nigel if/when you need it)<br />
<br />
The function json_reply($error, $message) will set the appropriate headers and send the json encoded array with the error and message fields set, for example,<br />
<br />
<div class="plugin tightenable"><code><font color="#000000"> <font color="#007700">function </font><font color="#0000bb">fooform_submit</font><font color="#007700">(</font><font color="#0000bb">Pieform $form</font><font color="#007700">, </font><font color="#0000bb">$values</font><font color="#007700">) {<br /> </font><font color="#0000bb">set_config</font><font color="#007700">(</font><font color="#dd0000">'foo'</font><font color="#007700">, </font><font color="#0000bb">$values</font><font color="#007700">[</font><font color="#dd0000">'foo'</font><font color="#007700">]);<br /> </font><font color="#0000bb">$form</font><font color="#007700">-&gt;</font><font color="#0000bb">json_reply</font><font color="#007700">(</font><font color="#0000bb">PIEEFORM_OK</font><font color="#007700">, </font><font color="#0000bb">get_string</font><font color="#007700">(</font><font color="#dd0000">'setfoosuccessfully'</font><font color="#007700">));<br /> }<br /></font> </font> </code></div><br />
<br />
If the submission was successful, then the js function named in 'jssuccesscallback' will be called. 'jsfailurecallback' is also available, should you need it.<br />
<br />
</div></div>
Brettwilkins