<?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>EaseMarry Blogs &#187; Framework</title>
	<atom:link href="http://www.easemarry.com/blog/category/php/framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.easemarry.com/blog</link>
	<description>php and java code</description>
	<lastBuildDate>Sun, 09 Aug 2009 16:09:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solar Form Validation Types</title>
		<link>http://www.easemarry.com/blog/solar-form-validation-types/</link>
		<comments>http://www.easemarry.com/blog/solar-form-validation-types/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 10:17:37 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solar]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/solar-form-validation-types/</guid>
		<description><![CDATA[
This is partially for my reference and partially for anyone looking at validating in their Solar_Form forms &#8211; here&#8217;s the validation methods (as defined in /Solar/Filter.php):
Each of these can be used when defining the form, commonly in the setElements structure like so:


?View Code PHP1
2
3
4
5
6
7
8
9
10
11
$form = Solar::factory&#40;'Solar_Form'&#41;;
$form-&#62;setElements&#40;array&#40;
    'password'=&#62;array&#40;
      [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
This is partially for my reference and partially for anyone looking at validating in their <a href="http://solarphp.com/class/Solar_Form"><strong><font color="#325c76">Solar_Form</font></strong></a> forms &#8211; here&#8217;s the validation methods (as defined in <a target="_blank" href="http://www.easemarry.com/blog">/Solar/Filter.php):</a></p>
<p>Each of these can be used when defining the form, commonly in the setElements structure like so:</p>
<p><span id="more-22"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p22code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p222"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p22code2"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> Solar<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Solar_Form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setElements</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'password'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'require'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'valid'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
            <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notBlank'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Enter a password!'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<table border="0" cellPadding="0" cellSpacing="0" id="reftable">
<tr>
<td class="header"><strong>Type</strong></td>
<td class="header"><strong>Details</strong></td>
</tr>
<tr>
<td>alnum</td>
<td>Validate that valid is only alphabetic and numeric characters</td>
</tr>
<tr>
<td>alpha</td>
<td>Validate that value is only alphabetic</td>
</tr>
<tr>
<td>blank</td>
<td>Validate that there&#8217;s nothing in the field, it&#8217;s blank</td>
</tr>
<tr>
<td>callback</td>
<td>Validate against a callback function &#8211; call is given the value and callback function name</td>
</tr>
<tr>
<td>ctype</td>
<td>Checks the value with the ctype_* function built into PHP</td>
</tr>
<tr>
<td>email</td>
<td>Validates as a valid email address</td>
</tr>
<tr>
<td>feedback</td>
<td>Validates and only returns a message on failure, returns feedback as a string</td>
</tr>
<tr>
<td>inKeys</td>
<td>Validate that the value is one of the keys of the given array</td>
</tr>
<tr>
<td>inList</td>
<td>Validates that the entered value is in a given array (as value, not key)</td>
</tr>
<tr>
<td>integer</td>
<td>Checks to ensure that the value is an integer (contains + or &#8211; and numbers, no decimals)</td>
</tr>
<tr>
<td>ipv4</td>
<td>Validates to check for a correct ipv4 address</td>
</tr>
<tr>
<td>isoDate</td>
<td>Ensures that value is a correctly formatted ISO 8601 date (yyyy-mm-dd)</td>
</tr>
<tr>
<td>isoTime</td>
<td>Validates that value is a correct ISO 8601 time format (HH:MM:SS)</td>
</tr>
<tr>
<td>isoTimestamp</td>
<td>Validates that value matches the full ISO 8601 timestamp format (yyyy-mm-ddThh:ii:ss)</td>
</tr>
<tr>
<td>localeCode</td>
<td>Checks to see if the value is a valid locale code (two a-z letters, an underscore and two A-Z letters)</td>
</tr>
<tr>
<td>max</td>
<td>Checks to see if the given value is greater than or equal to the &#8216;max&#8217; given</td>
</tr>
<tr>
<td>maxLength</td>
<td>Checks the value to ensure that it&#8217;s less than or equal to the maximum length given</td>
</tr>
<tr>
<td>mimeType</td>
<td>Checks to see if the value is a valid mime type (follows the regular expression: [a-zA-Z][-.a-zA-Z0-9+]*)</td>
</tr>
<tr>
<td>min</td>
<td>Checks to see if the value given is less than or equal to a minimum</td>
</tr>
<tr>
<td>minLength</td>
<td>Checks the value to be sure it&#8217;s at least a minimum length</td>
</tr>
<tr>
<td>multiple</td>
<td>Allows you to perform multiple validations on the same value</td>
</tr>
<tr>
<td>notZero</td>
<td>Ensures that the value does not exactly equal zero</td>
</tr>
<tr>
<td>notBlank</td>
<td>Ensure that a string, when trimmed, is not empty</td>
</tr>
<tr>
<td>range</td>
<td>Ensure that the value given is in a certain range</td>
</tr>
<tr>
<td>rangeLength</td>
<td>Validate that the length of the given value is within a certain range</td>
</tr>
<tr>
<td>regex</td>
<td>Match the value against a given regular expression</td>
</tr>
<tr>
<td>scope</td>
<td>Checks to be sure that the given value only has a certain number of digits and decimals</td>
</tr>
<tr>
<td>sepWords</td>
<td>Validate that the value is made up of separate words</td>
</tr>
<tr>
<td>uri</td>
<td>Validate that the input is a valid URI</td>
</tr>
<tr>
<td>word</td>
<td>Ensure that the value is made up of only &#8220;word&#8221; characters</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/solar-form-validation-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Form Helpers in Solar</title>
		<link>http://www.easemarry.com/blog/custom-form-helpers-in-solar/</link>
		<comments>http://www.easemarry.com/blog/custom-form-helpers-in-solar/#comments</comments>
		<pubDate>Sun, 09 Mar 2008 09:39:04 +0000</pubDate>
		<dc:creator>rueben</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Development]]></category>
		<category><![CDATA[Calendar Helper]]></category>
		<category><![CDATA[Creation]]></category>
		<category><![CDATA[Familiar Territory]]></category>
		<category><![CDATA[Form Javascript]]></category>
		<category><![CDATA[Helper Class]]></category>
		<category><![CDATA[Javascript Popup]]></category>
		<category><![CDATA[Mysite]]></category>
		<category><![CDATA[php framework]]></category>
		<category><![CDATA[Solar]]></category>
		<category><![CDATA[Solar framework]]></category>

		<guid isPermaLink="false">http://www.easemarry.com/blog/custom-form-helpers-in-solar/</guid>
		<description><![CDATA[
Another thing that Solar makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.
In a previous post, I worked some with the Solar_Form class to create a login [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#co-2--><br />
Another thing that <a href="http://www.solarphp.com/"><font color="#999999">Solar</font></a> makes easy is the creation of custom form helpers. These can be anything outside of the usual input types (like text, checkbox, textarea, etc) and can be used to make helpful, more complex inputs for your app.</p>
<p>In a <a href="http://blog.phpdeveloper.org/?p=65"><strong><font color="#325c76">previous post</font></strong></a>, I worked some with the <a href="http://solarphp.com/package/Solar_Form"><strong><font color="#325c76">Solar_Form class</font></strong></a> to create a login form. This just used simple input fields (text and password) to create the login form. I came to another part of my application where I needed a calendar helper to fill in some fields. I wanted to eliminate some of the user issues that could come with invalid dates being entered, so I opted to create a custom form field instead. The field is a normal text field, marked as READONLY with a link that launches a Javascript popup with the calendar picker.</p>
<p><span id="more-21"></span></p>
<p>First, we need a little structure &#8211; here&#8217;s how the application is structured (basically):</p>
<pre>MyApp</pre>
<pre>  App</pre>
<pre>   Base</pre>
<pre>    Helper</pre>
<pre>     FormDate.php</pre>
<pre>    Layout</pre>
<pre>    Locale</pre>
<pre>    View</pre>
<pre>   Event</pre>
<pre>   Event.php</pre>
<pre>    Helper</pre>
<pre>    Layout</pre>
<pre>    Locale</pre>
<pre>    View</pre>
<pre>     index.php</pre>
<p>There&#8217;s a few things involved here:</p>
<ul>
<li>The form helper class &#8211; <a target="_blank" href="http://www.easemarry.com/blog">FormDate.php</a></li>
<li>The <a href="http://www.easemarry.com/blog">Event.php</a> class (controller) where the form will be created</li>
<li>The View for the Event controller to output the form and some Javascript</li>
</ul>
<p>We&#8217;ll start with building the form since that&#8217;s more familiar territory:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code6'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p216"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p21code6"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySite_App_Event <span style="color: #000000; font-weight: bold;">extends</span> MySite_App_Base <span style="color: #009900;">&#123;</span>
    protected   <span style="color: #000088;">$_action_default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
    protected   <span style="color: #000088;">$_layout</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
    protected   <span style="color: #000088;">$_view</span>  <span style="color: #339933;">=</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span>    <span style="color: #000088;">$forms</span><span style="color: #339933;">;</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> actionIndex<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> Solar<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Solar_Form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setElements</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'event_title'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Event Title'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'require'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'valid'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                    <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notBlank'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Please enter an event title!'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'event_start'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span>   <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'date'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label'</span>  <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Start Date'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'require'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'valid'</span>  <span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                    <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'notBlank'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Please select a start date!'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'sub'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'submit'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'value'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'create event'</span>
            <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feedback</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'create_form'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you look close, you&#8217;ll spot something custom in there &#8211; on the event_start element, there&#8217;s a type of &#8220;date&#8221;. This how our special form helper is called. Solar does a little magic here &#8211; it looks at the types of each of the elements and looks in a few places for something that matches that type. Most of the elements are Solar&#8217;s default types so it falls back to the ones in the Solar directories. The &#8220;date&#8221; type, however, isn&#8217;t one of them and the app will break if you leave it like this.</p>
<p>So, what&#8217;s a developer to do? Well, create a custom form handler of course! This is where the FormDate.php file comes into play. Here&#8217;s what ours contains:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p217"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p21code7"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MySite_App_Base_Helper_FormDate <span style="color: #000000; font-weight: bold;">extends</span> Solar_View_Helper_FormElement <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> formDate<span style="color: #009900;">&#40;</span><span style="color: #000088;">$info</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>_prepare<span style="color: #009900;">&#40;</span><span style="color: #000088;">$info</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot;'</span>
             <span style="color: #339933;">.</span> <span style="color: #0000ff;">' name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-/&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_name<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: #0000ff;">' value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_value<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;">$this</span><span style="color: #339933;">-&gt;</span>_view<span style="color: #339933;">-&gt;</span><span style="color: #004000;">attribs</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_attribs<span style="color: #009900;">&#41;</span>
             <span style="color: #339933;">.</span> <span style="color: #0000ff;">' READONLY/&gt; &lt;a href=&quot;#&quot; onClick=&quot;date_picker('</span><span style="color: #0000ff;">'.$this-&gt;_view-&gt;escape($this-&gt;_name).'</span><span style="color: #0000ff;">')&quot;&gt;select&lt;/a&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you&#8217;ve been checking out the default Solar form fields, this should look familiar &#8211; it&#8217;s a ripoff of the default text field form helper that Solar comes with. The only addition is the Javascript-powered link there at the end that calls the date_picker application.</p>
<p>There&#8217;s a few things that need to be in place to get this to work. First off, the <strong><a href="http://www.easemarry.com/blog">class name</a></strong> needs to be the right &#8220;path&#8221; to the file. So, for our class it corresponds to MySite/App/Base/Helper to tell Solar where the file exists. If this isn&#8217;t right, Solar won&#8217;t be able to find and use the file. Next thing to look out for is the last part of the class name &#8211; FormDate for us. The second part of this is what Solar uses when the class is called. So, for example, we use FormDate because we want the type to be &#8220;date&#8221;. If we wanted one that was some kind of special field that works with Google&#8217;s Maps, we could use FormGoogle and define our custom form field inside it. Speaking of inside, the <strong><a href="http://www.easemarry.com/blog">method&#8217;s name</a></strong> has to match the class name &#8211; FormDate and formDate &#8211; and takes in the information passed to it (including the field name, the value to fill it with and attributes it might have).</p>
<p>Because this file exists in the Base controller&#8217;s Helper directory and our Event class extends the Base, we can use it. Plus, by putting it up in the Base Helper directory, we can use it in other places in the site that extend Base.</p>
<p>Now we&#8217;ll move on to the last part of the equation &#8211; the View for the Event controller:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p218"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p21code8"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">function</span> date_picker<span style="color: #009900;">&#40;</span>fname<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    elem<span style="color: #339933;">=</span>document<span style="color: #339933;">.</span>getElementById<span style="color: #009900;">&#40;</span>fname<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    elem<span style="color: #339933;">.</span>value<span style="color: #339933;">=</span><span style="color: #0000ff;">'08/14/1977'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span> 
<span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'create_form'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In the View above (our index.php file), we define the Javascript function our custom helper will use &#8211; date_picker &#8211; that takes in the element name. In a real application, this would be the place to interface with another page (or maybe even some sort of Ajax request) to let the user pick the date. As it stands, though, we&#8217;re just putting our predefined date in the field. The PHP part is simple, just an execution of the form. </p>
<p>Ideally, you&#8217;d put any and all Javascript in a few files out in the public directory of your application rather than in the view itself, but since we&#8217;re going for simplicity here I&#8217;ve just put it in the page itself. </p>
<p>So, there we go &#8211; a simple method to make a custom form handler that you can use anywhere in your application. It&#8217;s pretty easy to see how you can expand upon this to make just about any kind of custom form element that you might want&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.easemarry.com/blog/custom-form-helpers-in-solar/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

