<?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; PHP</title>
	<atom:link href="http://www.akchauhan.com/tag/php/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>Sun, 04 Jul 2010 20:19:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Verify the iTunes Account access information with the help of cURL</title>
		<link>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/</link>
		<comments>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 20:19:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[iTunes]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=646</guid>
		<description><![CDATA[&#60;?php // URLs of iTunesconnect. $urlBase = 'https://itts.apple.com'; $urlWebsite = $urlBase . '/cgi-bin/WebObjects/Piano.woa'; &#160; // function to check finance role acounts validity. This function return true is the detail is still valid. function isAccountValid&#40;$username, $password&#41; &#123; global $urlBase, $urlWebsite; &#160; $html = curlRequest&#40;$urlWebsite, null&#41;; // First cURL request to get the login form &#160; preg_match&#40;'/&#34; [...]]]></description>
			<content:encoded><![CDATA[
<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: #666666; font-style: italic;">// URLs of iTunesconnect.</span>
<span style="color: #000088;">$urlBase</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://itts.apple.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$urlWebsite</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$urlBase</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/cgi-bin/WebObjects/Piano.woa'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// function to check finance role acounts validity. This function return true is the detail is still valid.</span>
<span style="color: #000000; font-weight: bold;">function</span> isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$urlBase</span><span style="color: #339933;">,</span> <span style="color: #000088;">$urlWebsite</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$urlWebsite</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// First cURL request to get the login form</span>
&nbsp;
	<span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot; action=&quot;.*&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Search the form action URL because all URLs are dynamic</span>
&nbsp;
	<span style="color: #000088;">$urlActionLogin</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$urlBase</span> <span style="color: #339933;">.</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$postData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theAccountName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theAccountPW'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.Continue.x'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.Continue.y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Creating the form POST data</span>
&nbsp;
	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$urlActionLogin</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Second cURL request with form data for login</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Report Options'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If the return HTML contain 'Report Options' text then its successful login</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// function send the curl request on given URL with post variables and return the html output</span>
<span style="color: #000000; font-weight: bold;">function</span> curlRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$postVars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_FOLLOWLOCATION<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
 	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_SSL_VERIFYPEER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_errno</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Examples 01</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'anil@test.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test@anil'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;anil@test.com account is valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;anil@test.com account is not valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Examples 02</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isAccountValid<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'invalid_address@test.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wrong_password'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;invalid_address@test.com account is valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;invalid_address@test.com account is not valid.&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/verify-the-itunes-account-access-information-with-the-help-of-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a TinyURL using PHP and TinyURL API</title>
		<link>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/</link>
		<comments>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 07:30:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[TinyUrl]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=591</guid>
		<description><![CDATA[TinyURL is an awesome service. For those who don&#8217;t know what TinyURL is, TinyURL allows you to convert your long URLs like &#8220;http://www.akchauhan.com/category/jquery/&#8221; to small URLs like &#8220;http://tinyurl.com/yz4c4ba&#8221;. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>TinyURL </strong>is an awesome service. For those who don&#8217;t know what <strong>TinyURL </strong>is, <strong>TinyURL </strong>allows you to convert your long URLs like <strong>&#8220;http://www.akchauhan.com/category/jquery/&#8221;</strong> to small URLs like <strong>&#8220;http://tinyurl.com/yz4c4ba&#8221;</strong>. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of characters you can post like <strong>Twitter</strong>. Twitter only allow 140 characters long Tweet.</p>
<p>Using the PHP and TinyURL API, you can create these tiny URLs.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>  
<span style="color: #009900;">&#123;</span>  
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #0000ff;">'http://tinyurl.com/api-create.php?url='</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span><span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//test it out!</span>
<span style="color: #000088;">$new_url</span> <span style="color: #339933;">=</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.akchauhan.com/category/jquery/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//returns http://tinyurl.com/yz4c4ba</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_url</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create Random Alphanumeric Password in PHP</title>
		<link>http://www.akchauhan.com/create-random-alphanumeric-password-in-php/</link>
		<comments>http://www.akchauhan.com/create-random-alphanumeric-password-in-php/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 08:16:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Password]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=585</guid>
		<description><![CDATA[We can use this simple password generation function to create random passwords. The maximum limit of generated password is 36 characters. &#60;?php function gen_password&#40;$size = 8&#41; &#123; $size = $size &#62; 36 ? 30 : $size; $pool = array_merge&#40;range&#40;0, 9&#41;, range&#40;'A', 'Z'&#41;&#41;; $rand_keys = array_rand&#40;$pool, $size&#41;; &#160; $password = ''; &#160; foreach &#40;$rand_keys as $key&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>We can use this simple password generation function to create random passwords. The maximum limit of generated password is 36 characters.</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: #000000; font-weight: bold;">function</span> gen_password<span style="color: #009900;">&#40;</span><span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">36</span> ? <span style="color: #cc66cc;">30</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$size</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pool</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Z'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$rand_keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_rand</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pool</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rand_keys</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$pool</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> gen_password<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We can use it like 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;">$password</span> <span style="color: #339933;">=</span> gen_password<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</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/create-random-alphanumeric-password-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create Windows Service to Schedule PHP Script execution</title>
		<link>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/</link>
		<comments>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 15:02:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[Job Schedule]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=560</guid>
		<description><![CDATA[If you want to schedule your PHP script or any other command on Windows Platform recursively after a fix interval of time then you can create a Windows Service for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using C# language for this scheduler service you can also use VB.net for [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to schedule your PHP script or any other command on <strong>Windows Platform</strong> recursively after a fix interval of time then you can create a <strong>Windows Service</strong> for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using <strong>C#</strong> language for this scheduler service you can also use <strong>VB.net</strong> for it. Basically we need this type of service if we want to execute some PHP script in background in a specific interval of time. For example, If you want to import data in bulk from some web service.</p>
<p>You need to follow these steps: -</p>
<ul>
<li>
Create a project by using the Windows Service application template. This template creates a class for you that inherits from ServiceBase and writes much of the basic service code, such as the code to start the service.</li>
<li>
Write the code for the OnStart and OnStop procedures, and override any other methods that you want to redefine.
</li>
<li>
Add the necessary installers for your service application. By default, a class that contains two or more installers is added to your application when you click the Add Installer link: one to install the process, and one for each associated service that your project contains.
</li>
<li>
Build your project.
</li>
<li>
Create a setup project to install your service, and then install it.
</li>
<li>
Access the Windows 2000 Services Control Manager and start your service.
</li>
</ul>
<p>For more detail check &#8220;<strong>Walkthrough: Creating a Windows Service Application in the Component Designer</strong>&#8221; topic in <strong>MSDN</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">using <span style="color: #990000;">System</span><span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Collections<span style="color: #339933;">.</span>Generic<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ComponentModel<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Data<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Linq<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ServiceProcess<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Text<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> MyNewService
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> partial <span style="color: #000000; font-weight: bold;">class</span> MyNewService <span style="color: #339933;">:</span> ServiceBase
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> Timer syncTimer <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> MyNewService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        protected override void OnStart<span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Interval <span style="color: #339933;">=</span> <span style="color: #cc66cc;">180000</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Elapsed <span style="color: #339933;">+=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">.</span>ElapsedEventHandler<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>syncTimer_Tick<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        protected override void OnStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> void syncTimer_Tick<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> EventArgs e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">.</span>Process<span style="color: #339933;">.</span>Start<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs<span style="color: #000099; font-weight: bold;">\t</span>ask.bat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>  
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The <strong>task.bat</strong> file is a batch file. We are executing our PHP script through this batch file. First we set the path of directory where php.exe is located in your windows. The <strong>import.php</strong> is basically importing data in bulk from some web and we need to execute this script file background in every 3 minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span><span style="color: #b1b100;">echo</span> off
cd\
set path<span style="color: #339933;">=</span>C<span style="color: #339933;">:</span>\xampp\php<span style="color: #339933;">;</span>
cd <span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs&quot;</span>
php import<span style="color: #339933;">.</span>php
<span style="color: #990000;">exit</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How use cURL library when running PHP through Command Line</title>
		<link>http://www.akchauhan.com/how-use-curl-library-when-running-php-through-command-line/</link>
		<comments>http://www.akchauhan.com/how-use-curl-library-when-running-php-through-command-line/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 23:40:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[curl]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=551</guid>
		<description><![CDATA[If you run any PHP code which using cURL extension through command line like this: c:\&#62;php somefile.php it might give error that &#8220;curl_init()&#8221; function is not defined. The reason is the cURL extension &#8220;php_curl.dll&#8221; is not loaded. So, to resolve this issue you can load cURL (or any extension) dynamically in your PHP code. The [...]]]></description>
			<content:encoded><![CDATA[<p>If you run any <strong>PHP code</strong> which using <strong>cURL extension</strong> through command line like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">c<span style="color: #339933;">:</span>\<span style="color: #339933;">&gt;</span>php somefile<span style="color: #339933;">.</span>php</pre></div></div>

<p> it might give error that &#8220;<strong>curl_init()</strong>&#8221; function is not defined. The reason is the cURL extension &#8220;<strong>php_curl.dll</strong>&#8221; is not loaded. So, to resolve this issue you can load cURL (or any extension) dynamically in your PHP code. The &#8220;<strong>dl()</strong>&#8221; basically load PHP extension at <strong>runtime</strong>.</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: #990000;">dl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php_curl.dll&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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/how-use-curl-library-when-running-php-through-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert XML to Array using DOM extension in PHP5</title>
		<link>http://www.akchauhan.com/convert-xml-to-array-using-dom-extension-in-php5/</link>
		<comments>http://www.akchauhan.com/convert-xml-to-array-using-dom-extension-in-php5/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 10:40:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=464</guid>
		<description><![CDATA[The xml2array class convert the XML stored in a string into an ARRAY. We are using the DOM extension of PHP5. The DOM extension replaced the DOM XML extension available in PHP4. The DOM XML extension is depreciated in PHP5. &#60;?php class xml2array &#123; &#160; function xml2array&#40;$xml&#41; &#123; if &#40;is_string&#40;$xml&#41;&#41; &#123; $this-&#62;dom = new DOMDocument; [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>xml2array</strong> class convert the <strong>XML</strong> stored in a string into an <strong>ARRAY</strong>. We are using the <strong>DOM extension</strong> of <strong>PHP5</strong>. The <strong>DOM </strong>extension replaced the <strong>DOM XML</strong> extension available in <strong>PHP4</strong>. The DOM XML extension is depreciated in PHP5.</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: #000000; font-weight: bold;">class</span> xml2array <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> xml2array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadXml</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> _process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
		<span style="color: #000088;">$occurance</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">childNodes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$occurance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeType</span> <span style="color: #339933;">==</span> XML_TEXT_NODE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">html_entity_decode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeValue</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">ENT_COMPAT</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
                                     <span style="color: #009900; font-weight: bold;">ENT_COMPAT</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'ISO-8859-15'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasChildNodes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">childNodes</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$children</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$child</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$children</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'#text'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$occurance</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'#text'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
						<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$child</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeName</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$child</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> 
&nbsp;
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasAttributes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
				<span style="color: #000088;">$attributes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">attributes</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$result</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;@&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$attr</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> getResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dom</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We can use this class like 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;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xml2array<span style="color: #009900;">&#40;</span><span style="color: #000088;">$XML_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$XML_array</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResult</span><span style="color: #009900;">&#40;</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/convert-xml-to-array-using-dom-extension-in-php5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create Drupal form using theme_table() like module list form (Part II)</title>
		<link>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/</link>
		<comments>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 13:12:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Form]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=452</guid>
		<description><![CDATA[This post is the second part of Create Drupal form using theme_table() like module list form post. In first part I have showed how we can create Drupal form like we have in Module list pages. In this post, I am showing how we disable some of the checkboxes so user can&#8217;t select them like [...]]]></description>
			<content:encoded><![CDATA[<p>This post is the second part of <a href="http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/" target="_blank"><strong>Create Drupal form using theme_table() like module list form</strong></a> post. In first part I have showed how we can create Drupal form like we have in Module list pages. In this post, I am showing how we disable some of the checkboxes so user can&#8217;t select them like we have for core modules in module list page. We can&#8217;t enable/disable core modules in module list.<br />
<div id="attachment_453" class="wp-caption aligncenter" style="width: 860px"><img src="http://www.akchauhan.com/wp-content/uploads/2009/06/orders.jpg" alt="Drupal Form using theme_table() function (Part II)" title="Drupal Form using theme_table() function (Part II)" width="850" height="220" class="size-full wp-image-453" /><p class="wp-caption-text">Drupal Form using theme_table() function (Part II)</p></div></p>
<p>Here I am just showing the changes which we require in code of Part I post.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</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;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkboxes'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Change this to </span>
&nbsp;
<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</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;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkboxes'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#process'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'expand_checkboxes'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'featured_disable'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#disabled_products'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$disabled</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In above code &#8220;<strong>$disabled</strong>&#8221; is an array containing the <strong>productid&#8217;s</strong> of all the products which we want to show as checked and in disable state. The structure of &#8220;<strong>$disabled</strong>&#8221; array is similar to <strong>&#8220;$status&#8221;</strong> array. We stored this array in <strong>&#8220;#disabled_products&#8221;</strong>. We also added <strong>&#8220;#process&#8221;</strong> in above code. </p>
<p><strong>&#8220;expand_checkboxes&#8221;</strong> and <strong>&#8220;featured_disable&#8221;</strong> are function names which Drupal call when create and render these checkboxes. <strong>&#8220;expand_checkboxes()&#8221;</strong> is defined in Drupal core files and we don&#8217;t need to define it again.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> featured_disable<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #000088;">$edit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#disabled_products'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  		<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#attributes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'disabled'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
&nbsp;
  	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>&#8220;featured_disable()&#8221;</strong> function is very important here. Drupal call this function when renders these checkboxes. Here we assigned <strong>&#8220;disabled&#8221;</strong> attribute to each checkbox which we want as disable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form-part-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How know recipient read the email or newsletter?</title>
		<link>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/</link>
		<comments>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 04:55:32 +0000</pubDate>
		<dc:creator>anil</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[GD Library]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=254</guid>
		<description><![CDATA[Sometimes we send the newsletters or emails to lot of peoples and we want to know how many of them read it. Normally the websites like Gmail, Yahoo, Hotmail don&#8217;t provide any facility for this purpose. But we can know that by sending HTML emails. HTML Emails &#8211; HTML emails are emails which can contain [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we send the newsletters or emails to lot of peoples and we want to know how many of them read it. Normally the websites like Gmail, Yahoo, Hotmail don&#8217;t provide any facility for this purpose. But we can know that by sending HTML emails. <br/><br/> <strong>HTML Emails</strong> &#8211; HTML emails are emails which can contain HTML tags in email body. Like &lt;table&gt;, &lt;tr&gt;, &lt;td&gt;, etc.<br/><br/> The main thing here is we need to send some information to our server when user open the email. So for this, we can place an image in email body and when user open this email the browser send request to our webserver for this image. We can also achieve this by adding <strong>javascript code</strong> or hidden <strong>iframe</strong> but normally email clients don&#8217;t support javascript code and iframes in email body and they strips out this unwanted code form email body. So, the best way to achieve this is by using images.<br/><br/></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: #666666; font-style: italic;">/*send_newsletter.php*/</span>
&nbsp;
<span style="color: #000088;">$newsletterid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// array of recipients</span>
<span style="color: #000088;">$recipients</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test1@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test2@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test3@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test4@gmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test5@gmail.com'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'test6@hotmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test7@hotmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test8@aol.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test9@aol.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test10@yahoo.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// subject</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Newsletter for April'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// message</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Newsletter for April&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;p&gt;This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. 
  This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. 
  This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. &lt;/p&gt;
  &lt;img src='http://www.akchauhan.com/newsletter_read.php?newsletterid=<span style="color: #006699; font-weight: bold;">{$newsletterid}</span>' height='1' width='1' /&gt;&lt;br/&gt;&lt;br/&gt;
  Thanks,&lt;br/&gt;
  www.akchauhan.com
&lt;/body&gt;
&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// To send HTML mail, the Content-type header must be set</span>
<span style="color: #000088;">$headers</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-type: text/html; charset=iso-8859-1'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'From: AKChauhan Blog &lt;anil@akchauhan.com&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipients</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Mail it</span>
	<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><br/></p>
<p>I have used a variable <strong>$newsletterid</strong> to track newsletter. We can also send some extra information in query string as per our requirement.<br/> Like</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.akchauhan.com/newsletter_read.php?newsletterid=$newsletterid&amp;userid=$userid</span></pre></div></div>

<p><br/></p>
<p><strong>Note:</strong> Here I have used <strong>mail()</strong> function only to make demonstration simple. mail() function is not suitable for sending large number of email in loop. Better we use <strong>PEAR::Mail</strong> or <strong>PEAR::Mail_Queue</strong> packages for sending large number of email.<br/><br/></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: #666666; font-style: italic;">/*newsletter_read.php*/</span>
&nbsp;
<span style="color: #000088;">$newsletterid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsletterid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*Write some code to update your read counter in your database. Or, do whatever you want to 
do when user open your newsletter.*/</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UPDATE info SET newsletter_count = newsletter_count + 1 WHERE newsletterid = '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$newsletterid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// We'll be outputting a JPEG</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/jpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images/one_pixel_small_white_image.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><br/></p>
<p>In above code, first we updated our newsletter read counter in database. We can do other things also like send an email to admin etc. as per requirement. Then we set the <strong>Content-Type</strong> to <strong>image/jpeg</strong> as we are going to send a jpeg image. So, we need to tell the browser about the content type of our response. Then, we created a 1 pixel white image usng GD library and outputted it to browser using <strong>imagejpeg()</strong> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>1</slash:comments>
		</item>
		<item>
		<title>Create Drupal form using theme_table() like module list form</title>
		<link>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/</link>
		<comments>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 18:03:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Form]]></category>

		<guid isPermaLink="false">http://blog.akchauhan.com/?p=110</guid>
		<description><![CDATA[I am showing here an example for Drupal form like you saw in Module list pages. I am considering here an example of Featured Product Management form so we can easily understand it. Step 1:- Create a menu hook for registering your page path. This registered path will display the featured product management page. &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>I am showing here an example for Drupal form like you saw in Module list pages.</p>
<div id="attachment_111" class="wp-caption aligncenter" style="width: 635px"><img class="size-full wp-image-111" title="Drupal Form using theme_table() function" src="http://www.akchauhan.com/wp-content/uploads/2009/03/drupal_from.jpg" alt="Drupal Form using theme_table() function" width="625" height="200" /><p class="wp-caption-text">Drupal Form using theme_table() function</p></div>
<p>I am considering here an example of Featured Product Management form so we can easily understand it.</p>
<p><strong>Step 1:-</strong> Create a menu hook for registering your page path. This registered path will display the featured product management page.</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: #000000; font-weight: bold;">function</span> product_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured_product_mgmt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		‘title’ <span style="color: #339933;">=&gt;</span> ‘Manage featured product’<span style="color: #339933;">,</span>
		‘page callback’ <span style="color: #339933;">=&gt;</span> ‘drupal_get_form’<span style="color: #339933;">,</span>
		‘page arguments’ <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’featured_product_form’<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		‘access arguments’ <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’access product’<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		‘type’ <span style="color: #339933;">=&gt;</span> MENU_CALLBACK<span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$items</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Step 2:- </strong>Create form object for your form. Here the important part is &#8220;featured&#8221; form element of type &#8220;checkboxes&#8221;. Checkboxes type is a group of checkbox and format a set of checkboxes. #options is an associative array, where the key is the #return_value of the checkbox and the value is displayed. We will store other information like name, category, discount etc. of product in form array so we can display it later.</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: #000000; font-weight: bold;">function</span> featured_product_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> “SELECT p<span style="color: #339933;">.*,</span> UNIX_TIMESTAMP<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">.</span>create_date<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">AS</span> create_date<span style="color: #339933;">,</span> c<span style="color: #339933;">.</span>name FROM <span style="color: #009900;">&#123;</span>product<span style="color: #009900;">&#125;</span> p LEFT <span style="color: #990000;">JOIN</span> <span style="color: #009900;">&#123;</span>category<span style="color: #009900;">&#125;</span> c ON p<span style="color: #339933;">.</span>cid <span style="color: #339933;">=</span> c<span style="color: #339933;">.</span>cid
	WHERE p<span style="color: #339933;">.</span>status <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span> ORDER BY p<span style="color: #339933;">.</span>product_name”<span style="color: #339933;">;</span>
	<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> db_query<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$featured_products</span> <span style="color: #339933;">=</span> featured_product<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> db_fetch_object<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ”<span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</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: #666666; font-style: italic;">#value’ =&gt; stripslashes($data-&gt;product_name));
</span>            <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</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: #666666; font-style: italic;">#value’ =&gt; stripslashes($data-&gt;name));
</span>            <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'discount'</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: #666666; font-style: italic;">#value’ =&gt; $data-&gt;discount . ‘%’);
</span>            <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'createdon'</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: #666666; font-style: italic;">#value’ =&gt; date(’m-d-Y’, $data-&gt;create_date));
</span>    
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$featured_products</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$status</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">productid</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</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: #666666; font-style: italic;">#type’ =&gt; ‘checkboxes’,
</span>		‘<span style="color: #666666; font-style: italic;">#options’ =&gt; $options,
</span>		‘<span style="color: #666666; font-style: italic;">#default_value’ =&gt; $status,
</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;">'submit'</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: #666666; font-style: italic;">#type’ =&gt; ’submit’,
</span>		‘<span style="color: #666666; font-style: italic;">#value’ =&gt; t(’Submit’),
</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;">'cancel'</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: #666666; font-style: italic;">#type’ =&gt; ‘markup’,
</span>		‘<span style="color: #666666; font-style: italic;">#value’ =&gt; l(t(’Cancel’), ‘dashboard’),
</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;">'#redirect'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ‘featured_product_mgmt’<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Step 3:-</strong> Create a form submit function. Any form submitted using the &#8220;submit&#8221; button will pass to their corresponding function if it is available. We will extract the user input from the form array and update our database accordingly.</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: #000000; font-weight: bold;">function</span> featured_product_form_submit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$form_values</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'values'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$featured</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form_values</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$selected_products</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$featured</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$selected_products</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> “<span style="color: #009900;">&#40;</span>’<span style="color: #000088;">$value</span>’<span style="color: #009900;">&#41;</span>”<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$value_string</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span>’<span style="color: #339933;">,</span><span style="color: #0000ff;">', $selected_products);
&nbsp;
	// Delete all previous featured products
	$query = “DELETE FROM {product_featured}”;
	db_query($query);
&nbsp;
	// Insert new featured products
	if (count($selected_products)) {
		$query = “INSERT INTO {product_featured}(productid) VALUES $value_string”;
		db_query($query);
	}
&nbsp;
	drupal_set_message(t(’Featured product list has been updated successfully.’));
}
?&gt;</span></pre></div></div>

<p><strong>Step 4:-</strong> Register your modules theme implementation using &#8220;hook_theme()&#8221; function.</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: #000000; font-weight: bold;">function</span> product_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		‘featured_product_form’ <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>‘arguments’ <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’form’ <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">NULL</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>Step 5:-</strong> Then finally define your theme function which actually format your form layout in list using the $form array. Using &#8220;foreach&#8221; loop we navigate through each item of $form array and create $rows array which we pass to &#8220;theme_table()&#8221; function later. Create the header of your table and call &#8220;table_theme()&#8221; function with $header and $rows parameters. Call the &#8220;drupal_render()&#8221; function for render the submit and cancel buttons.</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: #000000; font-weight: bold;">function</span> theme_featured_product_form<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$rows</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span>element_children<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'featured'</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: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’data’ <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$status</span><span style="color: #339933;">,</span> ‘<span style="color: #000000; font-weight: bold;">class</span>’ <span style="color: #339933;">=&gt;</span> ‘checkbox’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ‘‘<span style="color: #339933;">.</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>’‘<span style="color: #339933;">;</span>
			<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’data’ <span style="color: #339933;">=&gt;</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’data’ <span style="color: #339933;">=&gt;</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'discount'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’data’ <span style="color: #339933;">=&gt;</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'createdon'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$rows</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Individual table headers.</span>
	<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>’data’ <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span>’Featured’<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> ‘<span style="color: #000000; font-weight: bold;">class</span>’ <span style="color: #339933;">=&gt;</span> ‘checkbox’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span>’Name’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span>’Category’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span>’Discount’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$header</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span>’Created on’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> theme<span style="color: #009900;">&#40;</span>’table’<span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rows</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> drupal_render<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-drupal-form-using-theme_table-like-module-list-form/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
