<?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>Website Design Ireland, Website Development &#187; PHP create form fields function</title>
	<atom:link href="http://www.eire-webdesign.ie/blog/tag/php-create-form-fields-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eire-webdesign.ie/blog</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Sat, 02 Jan 2010 14:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Form creation and basic validation</title>
		<link>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/</link>
		<comments>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 14:41:51 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP create form fields function]]></category>
		<category><![CDATA[php forms]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/?p=119</guid>
		<description><![CDATA[As a developer and web designer,  the most frustrating part I have found  is when working with forms. Long time ago (about 2 years now) I start putting togheter few PHP function trying to make my life a lot easier, but never got the time to finish it off. Finally I have put everything on the side [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer and web designer,  the most frustrating part I have found  is when working with forms.<br />
Long time ago (about 2 years now) I start putting togheter few PHP function trying to make my life a lot easier, but never got the time to finish it off.</p>
<p>Finally I have put everything on the side and got cracking on this due to a new project that involves the making a few very long forms.</p>
<p>The thought of writing all the html code (tables or DIVs) and validate them made me go back to this little project and decided to give it more thoughts.</p>
<p>This is the first release of the PHP code for this project so, if you would like to give it a bash and make use of it please do so&#8230;</p>
<p>A sample can be found here: <a title="sample php form" href="http://www.eire-webdesign.ie/create_validate_form.php"><strong>SAMPLE PHP FORM</strong></a></p>
<p>Some of the features:</p>
<ul>
<li>Choice of using TABLE or DIVs for layout</li>
<li>You can create more than one form on the same page making sure the right one is validated on submission</li>
<li>Basic form validation</li>
<li>Option to make the field required or not</li>
<li>Show ERROR message  beside the required field &#8211; standard</li>
<li>Option to set the ERROR message text &#8211; set to REQUIRED in the sample form</li>
<li>Show ERROR message at the top of the form as well - optional</li>
<li>Cuts form creation time in more than half</li>
<li>Automatically sets the values of the field after posting the form</li>
<li>Option to add javascript code to the field (e.g. for use with ajax, etc)</li>
<li>and much more&#8230;</li>
</ul>
<p>If you find any errors and anything that could help improve the functionality of this project, please leave a comment and I&#8217;ll make sure it gets done ASAP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2010/01/02/php-form-creation-and-basic-validation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP create form fields</title>
		<link>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 20:22:29 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP create form fields function]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/</guid>
		<description><![CDATA[The other day I was looking for a solution to help me create a form without the hassle to check it again and again for missing arguments or miss-typing. Because i couldn&#8217;t find any ready made solutions I created this little function that made my life less miserable. I hope it could be useful to [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was looking for a solution to help me create a form without the hassle to check it again and again for missing arguments or miss-typing.<br />
Because i couldn&#8217;t find any ready made solutions I created this little function that made my life less miserable.</p>
<p>I hope it could be useful to you too.</p>
<pre lang="php">
/*
$ewd_type - could be text, password, submit, hidden, textarea or select
$ewd_name - the name and id of the input filed
$ewd_value - input value default or returned by post
$ewd_size - the size of the input type text
$ewd_cols - number of colums for the textarea type field - default = 30
$ewd_rows -  number of rows for the textarea type field - default = 6
*/    

function ewd_make_form_field($ewd_type,$ewd_name,$ewd_value='',$ewd_size='',$ewd_cols='',$ewd_rows=''){    

 global $_POST;
 $ewd_size = $ewd_size != "" ? $ewd_size : 30;
 $ewd_cols = $ewd_cols != "" ? $ewd_cols : 30;
 $ewd_rows = $ewd_rows != "" ? $ewd_rows : 6;
     

 switch ($ewd_type) {
  case "text":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' onfocus='this.style.borderColor=\"#0072BC\";' onblur='this.style.borderColor=\"silver\";' /&gt;";
   break;
  case "password":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' /&gt;";
   break;
  case "textarea":
   echo "&lt;textarea name='$ewd_name' id='$ewd_name' cols='$ewd_cols' rows='ewd_rows'&gt;$ewd_value&lt;/textarea&gt;";
   break;
  case "submit":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' value='$ewd_value' /&gt;";
   break;
  case "hidden":
   echo "&lt;input type='$ewd_type' name='$ewd_name' id='$ewd_name' value='$ewd_value' /&gt;";
   break;
  case "select":
   echo "&lt;select name='$ewd_name' id='$ewd_name'&gt; 
     &lt;option value=''&gt;Please Select&lt;/option&gt;";
     $ewd_y_value = explode(" ",$ewd_value);
     foreach ($ewd_y_value as $ewd_word) {
     echo "&lt;option value='$ewd_word'";
      if($ewd_word == trim($_POST[$ewd_name])){
       echo " selected='selected'";
      }
     echo "&gt;".$ewd_word."&lt;/option&gt;";
     }    

   echo "&lt;/select&gt;";
   break;
  default:
   echo "&lt;input type='text' name='$ewd_name' id='$ewd_name' size='$ewd_size' value='$ewd_value' /&gt;";
 }
}</pre>
<p>Method for using the above function:</p>
<pre lang="php">
&lt;form method="post" action="&lt;?php $_SERVER['REQUEST_URI'];?&gt;" name="x_form" id="x_form"&gt;
 &lt;table summary="some form"&gt;
  &lt;tr&gt;
   &lt;td colspan="2" style="background-color:#f5f5f5; padding:3px;"&gt;
    &lt;b&gt;About yourself&lt;/b&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Name:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','name',isset($_POST['name']) ? $_POST['name'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Surname:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','surname',isset($_POST['surname']) ? $_POST['surname'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Email:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','email',isset($_POST['email']) ? $_POST['email'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Phone:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('text','phone',isset($_POST['phone']) ? $_POST['phone'] : '');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td&gt;Type of Sale:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('select','sale_type','Private Garage Both');?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td valign="top"&gt;Extra details:&lt;/td&gt;
   &lt;td&gt;&lt;?php ewd_make_form_field('textarea','additional',isset($_POST['additional']) ? $_POST['additional'] : '');?&gt;(eg. Engine cc: 1.1 to 1.4)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
   &lt;td colspan="2" align="center"&gt;
    &lt;?php ewd_make_form_field('submit','submit','Send');?&gt;
    &lt;?php ewd_make_form_field('hidden','country','Ireland');?&gt;
   &lt;/td&gt;   
  &lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/10/19/php-create-form-fields/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
