Skip to content

Instantly share code, notes, and snippets.

@jtarleton
Created December 14, 2012 23:56
Show Gist options
  • Save jtarleton/4289715 to your computer and use it in GitHub Desktop.
Save jtarleton/4289715 to your computer and use it in GitHub Desktop.
Generic Symfony 1.x Form
<?php
class GenericSymfonyForm extends sfForm
{
static public $choices;
public function configure()
{
$this->disableCSRFProtection();
sfProjectConfiguration::getActive()->loadHelpers(array('Form'));
self::$choices=array('AL'=>'AL','AK'=>'AK');
$this->setWidgets(
array(
'_id' => new sfWidgetFormInputHidden(),
'address1' => new sfWidgetFormInputText( array('label' =>'Address 1'), array('class'=>'field') ),
'address2' => new sfWidgetFormInputText( array('label' =>'Address 2'), array('class'=>'field') ),
'city' => new sfWidgetFormInputText( array('label' =>'City'), array('class'=>'field') ),
'state' => new sfWidgetFormSelect( array('label' =>'State', 'choices'=>self::$choices), array('class'=>'') ),
'zip' => new sfWidgetFormInputText( array('label' =>'Zip'), array('class'=>'field','maxlength'=>5) ),
'phone' => new sfWidgetFormInputText( array('label' =>'Phone'), array('class'=>'field','maxlength'=>10) ),
'notes' => new sfWidgetFormTextarea( array('label' =>'Notes'), array('class'=>'field') )
)
);
$this->setValidators(
array(
'_id' => new sfValidatorNumber,
'address1' => new sfValidatorString,
'address2' => new sfValidatorPass,
'city' => new sfValidatorString,
'state' => new sfValidatorChoice(array('choices' => array_keys(self::$choices))),
'zip' => new sfValidatorNumber,
'phone' => new sfValidatorNumber,
'notes' => new sfValidatorPass
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment