<?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>devexp &#187; form</title>
	<atom:link href="http://www.devexp.eu/tag/form/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Fri, 28 Oct 2011 12:07:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Symfony Form: unsetAllFieldsExcept()</title>
		<link>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/</link>
		<comments>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 12:37:31 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=706</guid>
		<description><![CDATA[When creating forms in symfony which extends from a Base (ORM) class, you sometimes do not need all fields that Propel/Doctrine generates for you. If you want to remove them you have several ways to do so. 1. Unset the &#8230; <a href="http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>When creating forms in symfony which extends from a Base (ORM) class, you sometimes do not need all fields that Propel/Doctrine generates for you. If you want to remove them you have several ways to do so.</p>
<p><b>1. Unset the fiels you don&#8217;t need.</b></p>
<pre class="brush: php; title: ; notranslate">
public function configure() {
  unset($this['field1'], $this['field2'], ... );
}
</pre>
<p>Simple way to remove the fields you don&#8217;t want, but if you change something in your database, which has an impact on that form (new column, foreignkey, etc ), it will be added in the (generated) super class. And if you don&#8217;t update the unset function with that extra field, it will be expected in the form. Unless you have unit tests for all your forms this could brake it without knowing it.</p>
<p><b>2. Override the setup function.</b></p>
<pre class="brush: php; title: ; notranslate">
/**
 * @override
 */
public function setup()
  {
    parent::setup();

    $this-&gt;setWidgets(...);

    $this-&gt;setValidators(...);
  }
</pre>
<p>Another way is to override the setup function and do your own widgets and validators initialization. This is a good way to only intialize the fields you really need, but you&#8217;ll have to do what your ORM generated for you.</p>
<p><b>3. Use a function which unsets all fields except the one you need (like the enableAllPluginsExcept function).</b></p>
<pre class="brush: php; title: ; notranslate">
$this-&gt;unsetAllFieldsExcept(array(
      'field1',
      'field2',
      'field3',
      ...));
</pre>
<p>This would be usefull, because it will remove all fields you do not want to use, and even if new fields are added it will not use them. The drawback is that if you have 20 fields and only need to unset one of them, you&#8217;ll have more type work <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .<br />
Since it does not exist in symfony, I quickly created our own function. This function should be added in the class <u><em>BaseFormPropel.class</em></u>:</p>
<pre class="brush: php; title: ; notranslate">
abstract class BaseFormPropel extends sfFormPropel
{
  public function setup() {
  }

  protected function unsetAllFieldsExcept($fields = array()) {

    $unsetFields = array_diff(array_keys($this-&gt;getWidgetSchema()-&gt;getFields()), $fields);

    foreach($unsetFields as $value) {
      unset($this[$value]);
    }
  }
}
</pre>
<p><b>Which one to use ?</b><br />
None of them are better. But if you need to reset a majority of the fields the ORM has generated then I would go for the method 2. If you only need to unset the fields you do not want to use then I would use the function unsetAllFieldsExcept().</p>
<p>Which method do/would you use ?</p>
<div class="shr-publisher-706"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/27/symfony-form-unsetallfieldsexcept/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>sfWidgetFormInputCheckbox unchecked bug</title>
		<link>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/</link>
		<comments>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 12:33:37 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[sfWidgetFormInputCheckbox]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=681</guid>
		<description><![CDATA[Ever tried to create a Symfony form with a check box input field, which by default should be unchecked ? No ? Well read on because it&#8217;s not that easy . This would be the code to print a check &#8230; <a href="http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Ever tried to create a Symfony form with a check box input field, which by default should be unchecked ? No ? Well read on because it&#8217;s not that easy <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>This would be the code to print a check box input field in a Symfony form:</p>
<pre class="brush: php; title: ; notranslate">
class CheckboxForm extends BaseCheckboxForm {
 public function configure() {
 $this-&gt;widgetSchema['field'] = new sfWidgetFormInputCheckbox();
 }
}
</pre>
<p>When you use the form to create something then by default the check box should be unchecked. And when you use this form for editing, then the check box should be checked if the object you try to edit has already been checked in the past.</p>
<p>If you try this code, you&#8217;ll see that the check box will always be checked. Even if you display this form to create a new object. Strange no ?</p>
<p><span id="more-681"></span></p>
<p>The problem is due to a bug in the Symfony sfWidgetFormInputCheckbox class. Even worse, this bug has been reported the first time 10 months ago (<a href="http://trac.symfony-project.org/ticket/3917" target="_blank">trac #3917</a>) and 1 month later (<a href="http://trac.symfony-project.org/ticket/3996" target="_blank">trac #3996</a>) and it&#8217;s still not fixed ! (grrrrr)</p>
<p>Until Symfony bug fixes this issue, there are 2 work a rounds you can use.</p>
<p><strong>1. Edit the sfWidgetFormInputCheckbox class and patch it:</strong></p>
<p><em>actual</em></p>
<pre class="brush: php; title: ; notranslate">
class sfWidgetFormInputCheckbox extends sfWidgetFormInput
{
 ...
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false)
 {
 $attributes['checked'] = 'checked';
 }
 ...
 }
}
</pre>
<p><em>patched</em></p>
<pre class="brush: php; title: ; notranslate">
class sfWidgetFormInputCheckbox extends sfWidgetFormInput
{
 ...
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false &amp;&amp; $value != 0)
 {
 $attributes['checked'] = 'checked';
 }
 ...
 }
}
</pre>
<p>I would not recommend this, because if like us, you have more than one Symfony environment, there is a chance that you could forget to patch it. And worse if Symfony releases a new version without the bug fix you&#8217;ll have to remember to re patch the file.</p>
<p><strong>2. Extend the sfWidgetFormInputCheckbox class and override the render method:</strong></p>
<p><em>Edit: Put this class in the lib folder and call it myOwnWidgetFormInputCheckbox.class.php. After that run symfony cc.</em></p>
<pre class="brush: php; title: ; notranslate">
/**
 * FIXME: This class can be removed if the sfWidgetFormInputCheckbox bug
 * has been resolved in symfony.
 */
class myOwnWidgetFormInputCheckbox extends sfWidgetFormInputCheckbox
{
 /**
 * Override render method due to symfony bug (http://trac.symfony-project.org/ticket/3917)
 */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
 if (!is_null($value) &amp;&amp; $value !== false &amp;&amp; $value != 0)
 {
 $attributes['checked'] = 'checked';
 } 

 if (!isset($attributes['value']) &amp;&amp; !is_null($this-&gt;getOption('value_attribute_value'))) {
 $attributes['value'] = $this-&gt;getOption('value_attribute_value');
 }

 return parent::render($name, null, $attributes, $errors);
 }
}
</pre>
<p>Your form class should then be changed to:</p>
<pre class="brush: php; title: ; notranslate">
class CheckboxForm extends BaseCheckboxForm {
 public function configure() {
 $this-&gt;widgetSchema['field'] = new myOwnWidgetFormInputCheckbox();
 }
}
</pre>
<p>This was very easy to solve, but we lost a lot of time in finding the reason why this stupido check box was always checked. And why the hell is this bug still not solved in Symfony ?</p>
<p>In the mean time patch your symfony or create your own checkbox widget <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<div class="shr-publisher-681"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/04/23/sfwidgetforminputcheckbox-unchecked-bug/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Symfony Forms Framework: Merge 2 forms</title>
		<link>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/</link>
		<comments>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 11:02:22 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=462</guid>
		<description><![CDATA[Recently I had to create a form to create/update users in our system. Some time ago we decided to save are users in 2 tables. The first table would contain all login information and the second his personal information. This &#8230; <a href="http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Recently I had to create a form to create/update users in our system. Some time ago we decided to save are users in 2 tables. The first table would contain all login information and the second his personal information. This is a simple example of the DB design:</p>
<div id="attachment_463" class="wp-caption aligncenter" style="width: 498px"><img class="size-full wp-image-463" title="User db design" src="http://www.devexp.eu/wp-content/uploads/2009/03/dbdesign.png" alt="User db design" width="488" height="168" /><p class="wp-caption-text">User db design</p></div>
<p>I would not recommend doing this for so little fields. But in our system we have a lot more fields, and it helps us to optimize our queries.</p>
<p>Wouldn&#8217;t it be better if we could merge the 2 forms? The answer is yes. And it&#8217;s pretty easy to do so in Symfony &#8230; too bad that it’s not documented on the Symfony website.</p>
<p><span id="more-462"></span></p>
<p>When you generate the forms with Symfony, you’ll get a UserForm and a UserInfoForm.</p>
<pre class="brush: php; title: ; notranslate">/**
* User form.
*
* @package    form
*/
class UserForm extends BaseUserForm {

public function configure() {

}

}

/**
* UserInfo form.
*
* @package    form
*/
class UserInfoForm extends BaseUserInfoForm {

public function configure() {

}

}</pre>
<p>The idea is to display one form to insert/update those 2 tables. If you are familiar to creating forms with Symfony you know that you could achieve it by instantiating the 2 forms in an action and send them to the templates:</p>
<pre class="brush: php; title: ; notranslate">
/**
* Action Class
*/
class userActions extends sfActions
{
public function executeCreate($request) {
$this-&gt;userForm = new UserForm();
$this-&gt;userInfoForm = new UserInfoForm();
$this-&gt;setTemplate('edit');
}

public function executeEdit($request) {
$this-&gt;userForm = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
$this-&gt;userInfoForm = new UserInfoForm(UserInfoPeer::retrieveByPK($request-&gt;getParameter('id')));
}

public function executeUpdate($request) {
$this-&gt;userForm = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
$this-&gt;userInfoForm = new UserInfoForm(UserInfoPeer::retrieveByPK($request-&gt;getParameter('id')));

$this-&gt;userForm-&gt;bind($request-&gt;getParameter($this-&gt;userForm-&gt;getName()));
$this-&gt;userInfoForm-&gt;bind($request-&gt;getParameter($this-&gt;userInfoForm-&gt;getName()));

// etc ...
}
}

// Template code editSuccess.php
&lt;?php $user = $userForm-&gt;getObject(); ?&gt;

&lt;form action=&quot;&lt;?php echo url_for('user/update'.(!$user-&gt;isNew() ? '?id='.$user-&gt;getId() : '')) ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;table&gt;
&lt;tfoot&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;
&lt;tbody&gt;
&lt;?php echo $userForm ?&gt;
&lt;?php echo $userInfoForm ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/form&gt;
</pre>
<p>This is really annoying to work this way. You always have to instance 2 forms in the action and the templates. Wouldn&#8217;t it be better if we could merge the 2 forms? The answer is yes. And it&#8217;s pretty easy to do so in Symfony &#8230; too bad that it’s not documented on the Symfony website.</p>
<p>Here is how you do it:</p>
<p><span style="text-decoration: underline;"><strong>1. UserForm.class.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">/**
* User form.
*
* @package    form
*/
class UserForm extends BaseUserForm {

public function configure() {
$this-&gt;mergeForm(new UserInfoForm(UserInfoPeer::retrieveByPK($this-&gt;getObject()-&gt;getId())));
}

/**
* Override the save method to save the merged user info form.
*/
public function save($con = null) {
parent::save();

$this-&gt;updateUserInfo();

return $this-&gt;object;
}

/**
* Updates the user info merged form.
*/
protected function updateUserInfo() {
// update user info
if (!is_null($userInfo = $this-&gt;getUserInfo())) {

$values = $this-&gt;getValues();
if ( $userInfo-&gt;isNew() ) {
$values['user_id'] = $this-&gt;object-&gt;getId();
}

$userInfo-&gt;fromArray($values, BasePeer::TYPE_FIELDNAME);

$userInfo-&gt;save();
}
}

/**
* Returns the user info object. If it does
* not exist return a new instance.
*
* @return UserInfo
*/
protected function getUserInfo() {

if (!$this-&gt;object-&gt;getUserInfo()) {
return new UserInfo();
}

return $this-&gt;object-&gt;getUserInfo();
}
}
</pre>
<p><span style="text-decoration: underline;"><strong>2. actions.class.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">
public function executeCreate($request) {
$this-&gt;form = new UserForm();
$this-&gt;setTemplate('edit');
}

public function executeEdit($request) {
$this-&gt;form = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));
}

public function executeUpdate($request) {

$this-&gt;forward404Unless($request-&gt;isMethod('post'));

$this-&gt;form = new UserForm(UserPeer::retrieveByPK($request-&gt;getParameter('id')));

$this-&gt;form-&gt;bind($request-&gt;getParameter($this-&gt;form-&gt;getName()));
if ($this-&gt;form-&gt;isValid()) {
$user = $this-&gt;form-&gt;save();
$this-&gt;redirect('user/edit?id='.$user-&gt;getId());
}

$this-&gt;setTemplate('edit');
}
</pre>
<p><span style="text-decoration: underline;"><strong>3. editSuccess.php</strong></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php $user = $userForm-&gt;getObject(); ?&gt;

&lt;form action=&quot;&lt;?php echo url_for('user/update'.(!$user-&gt;isNew() ? '?id='.$user-&gt;getId() : '')) ?&gt;&quot; method=&quot;post&quot;&gt;
&lt;table&gt;
&lt;tfoot&gt;
&lt;tr&gt;
&lt;td colspan=&quot;2&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;
&lt;tbody&gt;
&lt;?php echo $userForm ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/form&gt;
</pre>
<p>As you can see, it’s the UserForm that will handle all the business of the UserInfoForm. This is great because the code in the action and template will be much more lightened and if needed it can easily be reused somewhere else.</p>
<p>This was a simple example on how to merge 2 forms, but since it&#8217;s not documented on the symfony website, it took me some time to fully understand on how to make it work. Now you can do much more advanced operations. <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="shr-publisher-462"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/03/19/symfony-forms-framework-merge-2-forms/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Symfony Forms Framework: Change validators at runtime.</title>
		<link>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/</link>
		<comments>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 09:34:12 +0000</pubDate>
		<dc:creator>Van de Voorde Toni</dc:creator>
				<category><![CDATA[Framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=374</guid>
		<description><![CDATA[Let’s say you have to make a user form with password fields. When you create the user you want the password fields to be required, but on an update the password fields should be optional because you don’t want the &#8230; <a href="http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Let’s say you have to make a user form with password fields. When you create the user you want the password fields to be <strong>required</strong>, but on an update the password fields should be <strong>optional</strong> because you don’t want the user the fill in his password on each update.</p>
<p>This is tricky because in the symfony forms Framework you have to predefine your validators. Your form would look like this:</p>
<pre class="brush: php; title: ; notranslate">
class UserForm extends BaseUserForm {

  public function configure() {
    // Widgets
    $this-&gt;widgetSchema['password'] = new sfWidgetFormInputPassword();
    $this-&gt;widgetSchema['password_again'] = new sfWidgetFormInputPassword();

    // Validators
    $this-&gt;validatorSchema['password']-&gt;setOption('required', false);
    $this-&gt;validatorSchema['password_again'] = clone $this-&gt;validatorSchema['password'];

    $this-&gt;widgetSchema-&gt;moveField('password_again', 'after', 'password');

    $this-&gt;mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' =&gt; 'The two passwords must be the same.')));
  }

}
</pre>
<p>In this signature of the form I defined the password and password_again field as optional, which is correct for an update of the user, but incorrect for the creation of the user. How the hell can I change the validator of the password field when I create a user ?</p>
<p>Well thanks to the good and well designed framework of symfony it is very simple <img src='http://www.devexp.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<pre class="brush: php; title: ; notranslate">
class UserForm extends BaseUserForm {

  public function configure() {
    // Widgets
    $this-&gt;widgetSchema['password'] = new sfWidgetFormInputPassword();
    $this-&gt;widgetSchema['password_again'] = new sfWidgetFormInputPassword();

    // Validators
    $this-&gt;validatorSchema['password']-&gt;setOption('required', false);
    $this-&gt;validatorSchema['password_again'] = clone $this-&gt;validatorSchema['password'];

    $this-&gt;widgetSchema-&gt;moveField('password_again', 'after', 'password');

    $this-&gt;mergePostValidator(new sfValidatorSchemaCompare('password', sfValidatorSchemaCompare::EQUAL, 'password_again', array(), array('invalid' =&gt; 'The two passwords must be the same.')));
  }

  public function bind(array $taintedValues = null, array $taintedFiles = null) {

    if ( $this-&gt;object-&gt;isNew() ) {
      $this-&gt;validatorSchema['password']-&gt;setOption('required', true);
    }

    parent::bind($taintedValues, $taintedFiles);
  }

}
</pre>
<p>What I did is override the function <em>bind</em> and before calling the bind method of the parent, I checked if the user object is new (means that we create a user) and if this is the case set the required option of the password field to true. </p>
<div class="shr-publisher-374"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/02/15/symfony-forms-framework-change-validators-at-runtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>basic tips and tricks: 3.Forgotten form attributes</title>
		<link>http://www.devexp.eu/2009/01/16/basic-tips-and-tricks-3forgotten-form-attributes/</link>
		<comments>http://www.devexp.eu/2009/01/16/basic-tips-and-tricks-3forgotten-form-attributes/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 13:53:22 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[elements]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=273</guid>
		<description><![CDATA[A lot of people create easy forms but don’t think it trough before designing the page. I listed 5 useful attributes/elements a lot of people intend to forget or simply don’t know why they are using it. Use get or &#8230; <a href="http://www.devexp.eu/2009/01/16/basic-tips-and-tricks-3forgotten-form-attributes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>A lot of people create easy forms but don’t think it trough before designing the page. I listed 5 useful attributes/elements a lot of people intend to forget or simply don’t know why they are using it.</p>
<p>Use <strong>get or post</strong> to send a form</p>
<p>Get will append the form data to the URL that is set in the action attribute of the form and is used when the form is <a title="idempotent" href="http://en.wikipedia.org/wiki/Idempotent" target="_blank">idempotent</a>. For example on search forms.<br />
Post will not append it to the URL but sent it in the body of the form. It should be used when we are modifying a database or doing a subscription.</p>
<p>What is <strong>enctype</strong>?</p>
<p>This attribute is used to submit the form to the server; it is only needed when using post. Whenever you use a file field in your form you should set the enctype value to multipart/form-data, otherwise it uses the default value application/x-www-form-urlencoded.</p>
<p>Use <strong>tabindex</strong></p>
<p>This creates an order when going from one field to the next using your tab button. When creating complex forms, this might come in quite handy. It creates the opportunity for the developer to indicate the order the form needs to be completed. Every field in the form gets a ‘tabindex’ value starting from 0 with a maximum of 32767.</p>
<p>Connect a <strong>label to a field</strong></p>
<p>It’s always handy to have a label for each input field, so you can click on the label and the cursor automatically gets positioned in the input field. The only thing to do is put a ‘for’ attribute in the label and give it the id of the corresponding field as value. Easy and Handy for users</p>
<p><strong>Fieldset and legend</strong></p>
<p>This allows you to thematically group your form elements. The ‘legend’ element gives you the opportunity to create a title on each fieldset and has to be put in between the fieldset tags. Use css styling to create a nice design for the fieldset.</p>
<p>Greetings K.</p>
<div class="shr-publisher-273"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/01/16/basic-tips-and-tricks-3forgotten-form-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3 tips when using jQuery</title>
		<link>http://www.devexp.eu/2008/09/29/3-tips-when-using-jquery/</link>
		<comments>http://www.devexp.eu/2008/09/29/3-tips-when-using-jquery/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 09:52:18 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[live]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[submit]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=146</guid>
		<description><![CDATA[AjaxForm or ajaxSubmit This plug-in provides numerous options you can call to manage your form before and after submission and all this in AJAX. More info on http://malsup.com/jquery/form/ Live Query When an element is loaded into a page, you will &#8230; <a href="http://www.devexp.eu/2008/09/29/3-tips-when-using-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><strong>AjaxForm or ajaxSubmit</strong></p>
<p style="padding-left: 30px;">This plug-in provides numerous options you can call to manage your form before and after submission and all this in AJAX. More info on <a href="http://malsup.com/jquery/form/">http://malsup.com/jquery/form/</a></p>
<p><strong>Live Query</strong></p>
<p style="padding-left: 30px;">When an element is loaded into a page, you will not be able to use the events on this element. But when the Live Query is used, this magically appears to work&#8230; This is because the Live Query binds events of elements together every few milliseconds and does a DOM (<em>Document Object Model)</em> update. A really cool plug-in that creates the possibility for web developers to execute events without reloading the page every time an element is clicked. The only disadvantage of live query is the fact that it appears to slow down the execution time a bit, but when you don&#8217;t have to reload your page each time, I guess it&#8217;s worth the usage. More info on <a href="http://brandonaaron.net/docs/livequery/">http://brandonaaron.net/docs/livequery/</a></p>
<p><strong>JSON</strong> (<strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation)</p>
<p style="padding-left: 30px;">In our case we are using JSON as response-type from an AJAX request. This is a sort of XML but a lot easier to read, especially when you work with a lot of data. For more information on JSON visit <a href="http://json.org/">http://json.org/</a> or <a href="http://borkweb.com/story/the-case-for-json-what-is-it-and-why-use-it">http://borkweb.com/story/the-case-for-json-what-is-it-and-why-use-it</a></p>
<div class="shr-publisher-146"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2008/09/29/3-tips-when-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

