Created
December 14, 2012 23:56
-
-
Save jtarleton/4289715 to your computer and use it in GitHub Desktop.
Generic Symfony 1.x Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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