<?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>A K Chauhan's Blog &#187; Open Source</title>
	<atom:link href="http://www.akchauhan.com/tag/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Mon, 02 Jan 2012 03:29:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Assign attributes to options using FormAPI in Drupal</title>
		<link>http://www.akchauhan.com/assign-attributes-to-options-using-formapi-in-drupal/</link>
		<comments>http://www.akchauhan.com/assign-attributes-to-options-using-formapi-in-drupal/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 18:22:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.akchauhan.com/?p=130</guid>
		<description><![CDATA[Drupal FAPI does not support this feature but we can add attributes to options by slightly modifying form.inc file. You only need to change following line in form.inc file. &#60;?php $options .= '&#60;option value=&#34;'. check_plain&#40;$key&#41; .'&#34;'. $selected .'&#62;'. check_plain&#40;$choice&#41; .'&#60;/option&#62;'; //line no. 1437 of form_select_options() in drupal 6.10 ?&#62; with this &#60;?php $options .= '&#60;option [...]]]></description>
			<content:encoded><![CDATA[<p>Drupal FAPI does not support this feature but we can add attributes to options by slightly modifying form.inc file.</p>
<p>You only need to change following line in form.inc file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #000088;">$options</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;option value=&quot;'</span><span style="color: #339933;">.</span> check_plain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$selected</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span> 
				check_plain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$choice</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//line no. 1437 of form_select_options() in drupal 6.10</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>with this</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$options</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;option value=&quot;'</span><span style="color: #339933;">.</span> check_plain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$selected</span> <span style="color: #339933;">.</span> 
			drupal_attributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$element</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#options_attribute'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&gt;'</span><span style="color: #339933;">.</span> 
			check_plain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$choice</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/option&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>You can use like it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$shipping_methods</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Standard Two-Day ($17.00 Total Shipping Price)'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Priority Overnight ($26.00 Total Shipping Price)'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'3'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'FedEx Next Day Delivery $23.95'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'4'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'FedEx Next Day Delivery $23.95'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$shipping_method_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'1'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'17.00'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'2'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'26.00'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'two'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'3'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'23.95'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'three'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'4'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'23.95'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'four'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default_shipping_method'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'#title'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Shipping Method'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$shipping_methods</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'#options_attribute'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$shipping_method_options</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'default_shipping_method'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'#description'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You can change your shipping method from here.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/assign-attributes-to-options-using-formapi-in-drupal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

