<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I-Am-Bot &#187; code</title>
	<atom:link href="http://iambot.net/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://iambot.net</link>
	<description>Code, technology and life</description>
	<lastBuildDate>Tue, 10 Jan 2012 03:40:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Symfony2 form theme for Bootstrap</title>
		<link>http://iambot.net/2011/11/symfony2-form-theme-for-bootstrap/</link>
		<comments>http://iambot.net/2011/11/symfony2-form-theme-for-bootstrap/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 07:25:00 +0000</pubDate>
		<dc:creator>Srinath</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://iambot.net/?p=523</guid>
		<description><![CDATA[Symfony2 is a flexible, fast and secure PHP 5 framework for developing modern applications. This post assumes you already know the basics of working with Symfony. Symfony2 has a very powerful templating engine in the form of Twig, a simple templating engine much like the popular Mustache. Twig allows non programmers to quickly design HTML [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://symfony.com"><em>Symfony2</a> is a flexible, fast and secure PHP 5 framework for developing modern applications. This post assumes you already know the basics of working with Symfony.</em></p></blockquote>
<p>Symfony2 has a very powerful templating engine in the form of <a href="http://symfony.com/doc/current/book/templating.html">Twig</a>, a simple templating engine much like the popular Mustache. Twig allows non programmers to quickly design HTML layouts without the need to write PHP code. It also makes working with forms a breeze, and all that is needed to output a form on a template is</p>
<p><code>form_widget(form)</code></p>
<p>However, styling the form to suit your need takes a bit more effort. Symfony does allow your application to have different <a href="http://symfony.com/doc/2.0/cookbook/form/form_customization.html">form themes</a> which can be then be applied to various forms. It involves overriding various blocks to render different parts of the form. The problem is in finding which blocks to edit, and which to leave alone. This post can serve as a theme to render forms styled like the ones in <a href="http://twitter.github.com/bootstrap/">Bootstrap</a>.</p>
<p>When drawing a form using the <code>form_widget(form)</code> or <code>form_row(form.field)</code>, Symfony uses the default theme that is defined in the file <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig">form_div_layout.html.twig</a>. This file contains the various block definitions that are called when you use the appropriate twig function. For example, when you simply call <code>form_widget(form)</code>, you can see how it in turn calls <code>field_rows(form)</code>, which then renders the form errors, and for every field in the form, calls the corresponding widget block.</p>
<p>For Bootstrap's theme, we will override 3 blocks, and define one macro to display errors from the form.</p>
<p>We first define the macro hasErrors to check if the current field has an error, in which case the string "error" is returned which is appended to the class of the input div for the field to be rendered as an error field</p>
<p><code>/src/Acme/DemoBundle/Resources/views/Form/macro.html.twig</code></p>
<pre class="brush: xml; title: ; notranslate">
{% macro hasErrors(field) %}
    {% if form_errors(field)|length &gt; 1 %}
        {{ 'error' }}
    {% endif %}
{% endmacro %}
</pre>
<p>Then, we redefine the field_rows block and do not display the error messages at the beginning of the form</p>
<p><code>/src/Acme/DemoBundle/Resources/views/Form/theme.html.twig</code></p>
<pre class="brush: xml; title: ; notranslate">
{% block field_rows %}
{% spaceless %}
    {% for child in form %}
        {{ form_row(child) }}
    {% endfor %}
{% endspaceless %}
{% endblock field_rows %}
</pre>
<p>Next, we define the custom field_row block that actually renders the HTML for each field. We define the container div for each input field, and call the hasErrors macro to check if Symfony has returned an error for that field. If yes, the class "error" will be added to the class attribute, and the entire field will be highlighted in red to indicate an error. We then echo the error after the field, just like in Bootstrap. Notice how we are passing the global _context object to the form_widget block. By default, you can pass custom attributes to the form_widget block and not to the field_row block. This is done so that we can add custom attributes to each input field, as shown in the example at the end.</p>
<p><code>/src/Acme/DemoBundle/Resources/views/Form/theme.html.twig</code></p>
<pre class="brush: xml; title: ; notranslate">
{% block field_row %}
{% spaceless %}
    {% if macro is not defined %}
        {% import 'AcmeDemoBundle:Form:macro.html.twig' as macro %}
    {% endif %}
    &lt;div class=&quot;clearfix {{macro.hasErrors(form)}}&quot;&gt;
        {{ form_label(form) }}
        &lt;div class=&quot;input&quot;&gt;
            {{ form_widget(form, _context) }}
            {{ form_errors(form) }}
        &lt;/div&gt;
    &lt;/div&gt;
{% endspaceless %}
{% endblock field_row %}
</pre>
<p>We have defined the actual macro, but we now have to customize the error display. That is done in the field_errors block</p>
<p><code>/src/Acme/DemoBundle/Resources/views/Form/theme.html.twig</code></p>
<pre class="brush: xml; title: ; notranslate">
{% block field_errors %}
{% spaceless %}
    {% if errors is defined and errors|length &gt; 0 %}
        {% for error in errors %}
        &lt;span class=&quot;help-inline error&quot; style=&quot;float:right;width:170px;margin-top:5px;&quot;&gt;{{ error.messageTemplate|trans(error.messageParameters, 'validators') }}&lt;/span&gt;
        {% endfor %}
    {% endif %}
{% endspaceless %}
{% endblock field_errors %}
</pre>
<p>That's it! We have now created a custom form theme! To use this, just include the following twig block before drawing the theme</p>
<pre class="brush: xml; title: ; notranslate">
{% form_theme form 'AcmeDemoBundle:Form:theme.html.twig' %}
{{ form_row(form.name, { 'attr': {'class':'xlarge','placeholder':'Please enter your name'} }) }}
{{ form_row(form.description, {'attr': {'class':'xlarge'} }) }}
{{ form_rest(form) }}
</pre>
<p>We are using the form_row block to render each field, so that we can also pass along custom attributes to each field, just like the form_widget block <code>{{ form_widget(form.task, { 'attr': {'class': 'task_field'} }) }}</code>. However, if we use <code>form_widget(form)</code>, then custom attributes cannot be passed to individual fields, but the theme will be rendered nevertheless. Passing custom attributes is particularly useful to adjust the width, height, placeholder, etc of the fields.</p>
<p>That's it! You can define various themes for different parts of your application in a similar fashion, and simply set the appropriate theme with the <code>form_theme</code> directive before rendering a form. Have fun theming forms in Symfony2!</p>
]]></content:encoded>
			<wfw:commentRss>http://iambot.net/2011/11/symfony2-form-theme-for-bootstrap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update on phpUserAuth</title>
		<link>http://iambot.net/2011/08/update-on-phpuserauth/</link>
		<comments>http://iambot.net/2011/08/update-on-phpuserauth/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 07:42:12 +0000</pubDate>
		<dc:creator>Srinath</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://iambot.net/?p=492</guid>
		<description><![CDATA[My apologies for the lack of activity on phpUserAuth and a couple of other scripts. I have decided to spend sometime each week on my small projects, and to answer comments and questions regularly. As a first step towards that, phpUserAuth is now available on github. The project will be hosted there for better code [...]]]></description>
			<content:encoded><![CDATA[<p>My apologies for the lack of activity on phpUserAuth and a couple of other scripts. I have decided to spend sometime each week on my small projects, and to answer comments and questions regularly. As a first step towards that, phpUserAuth is now available on <a href="https://github.com/Checksum/phpUserAuth">github</a>. The project will be hosted there for better code management and it also makes it easier for other devs to contribute or customize it for their own needs. I realize that the code needs a lot of work, and some parts of it will have to rewritten from scratch. The immediate need is to cleanup some code, and improve the file organization. The commented JS source files will be uploaded and reorganized. </p>
<p>And to anyone who is using/planning to use it, I would like to know the most important feature that is needed immediately. That, along with enhancements to the admin page will be worked on. If anyone has already worked on enhancements, please put in a pull request on github.</p>
<p>Here's hoping for regular activity on the project!</p>
]]></content:encoded>
			<wfw:commentRss>http://iambot.net/2011/08/update-on-phpuserauth/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php-znisms released</title>
		<link>http://iambot.net/2010/11/php-znisms-released/</link>
		<comments>http://iambot.net/2010/11/php-znisms-released/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 15:39:15 +0000</pubDate>
		<dc:creator>Srinath</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[sms]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://iambot.net/?p=474</guid>
		<description><![CDATA[php-znisms is a PHP API for the SMS services provided by ZNISMS (currently only for India). This API can be used to send single or multiple messages, and check the account status. Requirements PHP version 5 or higher with support for CURL and SimpleXML Usage Detailed guide coming soon. Please see the file test.php for [...]]]></description>
			<content:encoded><![CDATA[<p>php-znisms is a PHP API for the SMS services provided by <a href="http://znisms.com">ZNISMS</a> (currently only for India). This API can be used to send single or multiple messages, and check the account status.</p>
<p><strong>Requirements</strong><br />
PHP version 5 or higher with support for CURL and SimpleXML</p>
<p><strong>Usage</strong><br />
Detailed guide coming soon. Please see the file test.php for details on how to use it</p>
<p><strong><a href="http://iambot.net/dScript/download.php?fname=./php-znisms.zip">Download</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://iambot.net/2010/11/php-znisms-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing TinyPop</title>
		<link>http://iambot.net/2010/08/introducing-tinypop/</link>
		<comments>http://iambot.net/2010/08/introducing-tinypop/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 11:34:58 +0000</pubDate>
		<dc:creator>Srinath</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://iambot.net/?p=434</guid>
		<description><![CDATA[&#160; TinyPop is a lightweight (1.5 KB minified) JavaScript for Growl like notifications. It can be used as an alternative to jGrowl when you don't want to use jQuery for a simple task. Details Download Demo]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>TinyPop is a lightweight (1.5 KB minified) JavaScript for <a href="http://en.wikipedia.org/wiki/Growl_%28software%29">Growl</a> like notifications. It can be used as an alternative to <a href="http://www.stanlemon.net/projects/jgrowl.html">jGrowl</a> when you don't want to use jQuery for a simple task. </p>
<p><strong><a href="http://iambot.net/projects/tinypop/">Details</a></strong></p>
<p><strong><a href="http://iambot.net/dScript/download.php?fname=./tinypop.zip">Download</a></strong></p>
<p><strong><a href="http://iambot.net/demo/tinypop/">Demo</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://iambot.net/2010/08/introducing-tinypop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpUserAuth Released!</title>
		<link>http://iambot.net/2010/07/phpuserauth-released/</link>
		<comments>http://iambot.net/2010/07/phpuserauth-released/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 02:04:13 +0000</pubDate>
		<dc:creator>Srinath</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://iambot.net/?p=426</guid>
		<description><![CDATA[It's finally done! The package is up for grabs, with a quick starter guide. Details Download Demo Please go through the project page for more details! The Readme.txt file inside folder "readme" contains instructions for installation and usage Leave your comments/questions/suggestions on the project page. Out.]]></description>
			<content:encoded><![CDATA[<p>It's finally done! The package is up for grabs, with a quick starter guide.</p>
<p><strong><a href="http://iambot.net/projects/phpuserauth/">Details</a></strong></p>
<p><strong><a href="http://iambot.net/dScript/download.php?fname=./phpuserauth.zip">Download</a></strong></p>
<p><strong><a href="http://iambot.net/demo/phpuserauth/">Demo</a></strong></p>
<p>Please go through the project page for more details!</p>
<p>The Readme.txt file inside folder "readme" contains instructions for installation and usage</p>
<p>Leave your comments/questions/suggestions on the project page.</p>
<p>Out.</p>
]]></content:encoded>
			<wfw:commentRss>http://iambot.net/2010/07/phpuserauth-released/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

