cvs: peardoc /en/package/html/html-quickform intro-migration32.xml
| From: | Alexey Borzov | Date: | Thu, 06 Nov 2003 15:58:01 +0000 |
| Subject: | cvs: peardoc /en/package/html/html-quickform intro-migration32.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-1883@lists.php.net to get a copy of this message | ||
avb Thu Nov 6 10:58:01 2003 EDT
Added files:
/peardoc/en/package/html/html-quickform intro-migration32.xml
Log:
This time, really added the guide
Index: peardoc/en/package/html/html-quickform/intro-migration32.xml
+++ peardoc/en/package/html/html-quickform/intro-migration32.xml
<!-- $Revision: 1.1 $ -->
<refentry id="package.html.html-quickform.intro-migration32">
<refnamediv>
<refname>Migration to version 3.2</refname>
<refpurpose>API changes to observe</refpurpose>
</refnamediv>
<refsect1 id="package.html.html-quickform.intro-migration32.overview">
<title>Why these changes?</title>
<para>
HTML_QuickForm has improved a lot since version 2.x. With the addition of a new renderer layer, a
lot of methods that were located in the main QuickForm class were actually duplicates of methods in
the renderers. Those methods were kept to give user time to adjust their code. With release 3.2 they
will be removed, making QuickForm class much lighter and consistent.
</para>
<para>
At the same time, file upload validation was moved to the file element as this is a more appropriate
place.
</para>
<para>Removed methods
<itemizedlist>
<listitem><para>QuickForm related
<itemizedlist>
<listitem><simpara><function>HTML_QuickForm::getAttributesString</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::addElementGroup</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::addHeader</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::addData</function></simpara></listitem>
</itemizedlist>
</para></listitem>
<listitem><para>Renderer related
<itemizedlist>
<listitem><simpara><function>HTML_QuickForm::setElementTemplate</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::setHeaderTemplate</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::setFormTemplate</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::setRequiredNoteTemplate</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::clearAllTemplates</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm_group::setElementTemplate</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm_group::setGroupTemplate</function></simpara></listitem>
</itemizedlist>
</para></listitem>
<listitem><para>File upload related
<itemizedlist>
<listitem><simpara><function>HTML_QuickForm::isUploadedFile</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::getUploadedFile</function></simpara></listitem>
<listitem><simpara><function>HTML_QuickForm::moveUploadedFile</function></simpara></listitem>
</itemizedlist>
</para></listitem>
</itemizedlist>
</para>
</refsect1>
<refsect1 id="package.html.html-quickform.intro-migration32.adjust">
<title>How to adjust your code</title>
<refsect2 id="package.html.html-quickform.intro-migration32.adjust.quickform">
<title>QuickForm related</title>
<variablelist>
<varlistentry>
<term><function>HTML_QuickForm::getAttributesString</function></term>
<listitem><para>
<programlisting role="php">
<![CDATA[
$form->getAttributes(true);
]]>
</programlisting>
will return the same value by using <function>HTML_Common::getAttributes</function>
method.
</para></listitem>
</varlistentry>
<varlistentry>
<term><function>HTML_QuickForm::addElementGroup</function></term>
<listitem><para>
Arguments order was changed to conform to the way elements are usually added to QuickForm by
<link
linkend="package.html.html-quickform.html-quickform.addelement"><function>addElement</function></link>.
Use <link
linkend="package.html.html-quickform.html-quickform.addgroup"><function>HTML_QuickForm::addGroup</function></link>
instead and swap the element label with the element name.
</para></listitem>
</varlistentry>
<varlistentry>
<term><function>HTML_QuickForm::addHeader</function></term>
<listitem><para>
A header is now considered like any other element. There is a new <link
linkend="package.html.html-quickform.html-quickform-header"><classname>HTML_QuickForm_header</classname></link>
element that extends <link
linkend="package.html.html-quickform.html-quickform-static"><classname>HTML_QuickForm_static</classname></link>.
Just use
<programlisting role="php">
<![CDATA[
$form->addElement('header', $header_name, $header_text);
]]>
</programlisting>
This will also allow you to customize the header rendering based on its name.
</para></listitem>
</varlistentry>
<varlistentry>
<term><function>HTML_QuickForm::addData</function></term>
<listitem><para>
If you absolutely need this feature, use
<programlisting role="php">
<![CDATA[
$form->addElement('html', $data)
]]>
</programlisting>
or consider using some template-based renderer.
</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect2 id="package.html.html-quickform.intro-migration32.adjust.renderer">
<title>Renderer related</title>
<para>
Those methods are now handled by the renderers. How to use these methods depends on your choice of
renderer. With QuickForm default renderer, you can use these methods like that:
<programlisting role="php">
<![CDATA[
$form =& new HTML_QuickForm('myform');
$renderer =& $form->defaultRenderer();
$renderer->setFormTemplate('<table><form{attributes}>{content}</form></table>');
$renderer->setHeaderTemplate('<tr><td
colspan="2"><b>{header}</b></td></tr>');
$renderer->setGroupTemplate('<table><tr>{content}</tr></table>');
$renderer->setGroupElementTemplate('<td>{element}<br /><!-- BEGIN required
-->*<!-- END required -->{label}</td>');
]]>
</programlisting>
<link
linkend="package.html.html-quickform.html-quickform.defaultrenderer"><function>defaultRenderer</function></link>will
return a reference to QuickForm integrated renderer. You can of course use <link
linkend="package.html.html-quickform.intro-renderers">any other renderer</link>
available in QuickForm such as Sigma, ITX, Smarty, Flexy and so on. Have a look at their
documentation to see which methods are available for them.
</para>
</refsect2>
<refsect2 id="package.html.html-quickform.intro-migration32.adjust.file">
<title>File upload related</title>
<para>
File-related methods and rules have been moved to the file element <link
linkend="package.html.html-quickform.html-quickform-file"><classname>HTML_QuickForm_file</classname></link>
because it makes more sense this way and you don't have to include upload-related code if you
are not using uploads. You have access to these methods like that:
<programlisting role="php">
<![CDATA[
$form = new HTML_QuickForm('myform');
$file =& $form->addElement('file', 'myfile', 'Your file:');
$form->addRule('myfile', 'Cannot exceed 1776 bytes', 'maxfilesize',
1776);
if ($file->isUploadedFile()) {
$file->moveUploadedFile('/tmp', 'testfile.txt');
}
]]>
</programlisting>
or like that:
<programlisting role="php">
<![CDATA[
$file =& $form->getElement('myfile');
if ($file->isUploadedFile()) {
$fileInfo = $file->getValue();
}
]]>
</programlisting>
</para>
</refsect2>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-executeMultiple-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->