| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
class CompanyForm extends BaseCompanyForm |
|---|
| 9 |
{ |
|---|
| 10 |
|
|---|
| 11 |
* Form configuration |
|---|
| 12 |
* |
|---|
| 13 |
*/ |
|---|
| 14 |
public function configure() |
|---|
| 15 |
{ |
|---|
| 16 |
unset($this['created_at'], |
|---|
| 17 |
$this['updated_at'], |
|---|
| 18 |
$this['slug'], |
|---|
| 19 |
$this['logo_path']); |
|---|
| 20 |
|
|---|
| 21 |
$this->initWidgets(); |
|---|
| 22 |
$this->initValidators(); |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
parent::setDefaults(array('homepage' => 'http://')); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
* Intitialize widgets |
|---|
| 30 |
* |
|---|
| 31 |
*/ |
|---|
| 32 |
public function initWidgets() |
|---|
| 33 |
{ |
|---|
| 34 |
$this->widgetSchema['country'] = new ExtendedWidgetFormI18nSelectCountry(array('culture' => $this->culture, 'add_label_option' => __('Select a country'))); |
|---|
| 35 |
$this->widgetSchema['logo_file'] = new sfWidgetFormInputFile(); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* Initialize validators |
|---|
| 40 |
* |
|---|
| 41 |
*/ |
|---|
| 42 |
public function initValidators() |
|---|
| 43 |
{ |
|---|
| 44 |
$this->validatorSchema['email'] = new sfValidatorAnd(array( |
|---|
| 45 |
new sfValidatorString(array('max_length' => 100, 'required' => true)), |
|---|
| 46 |
new sfValidatorEmail(array(), array('invalid' => __('This email address is invalid'))), |
|---|
| 47 |
)); |
|---|
| 48 |
$this->validatorSchema['city'] = new sfValidatorString(array('max_length' => 50, 'required' => true)); |
|---|
| 49 |
$this->validatorSchema['country'] = new sfValidatorI18nChoiceCountry(array('culture' => $this->culture, 'required' => true)); |
|---|
| 50 |
$this->validatorSchema['logo_file'] = new sfValidatorFile(array('max_size' => 512000, |
|---|
| 51 |
'mime_types' => 'web_images', |
|---|
| 52 |
'validated_file_class' => 'sfValidatedThumb', |
|---|
| 53 |
'required' => false)); |
|---|
| 54 |
$this->validatorSchema['homepage'] = new sfValidatorOr(array( |
|---|
| 55 |
new sfValidatorUrl(), |
|---|
| 56 |
new sfValidatorChoice(array('choices' => array('http://', ''))), |
|---|
| 57 |
), array(), array('invalid' => 'This url seems to be invalid')); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
$this->validatorSchema->setPostValidator(new sfValidatorAnd(array( |
|---|
| 61 |
new sfValidatorPropelUnique(array('model' => 'Company', 'column' => array('name'))), |
|---|
| 62 |
new sfValidatorOr(array( |
|---|
| 63 |
new sfValidatorSchemaFilter('homepage', new sfValidatorChoice(array('choices' => array('http://', ''), 'required' => false))), |
|---|
| 64 |
new sfValidatorPropelUnique(array('model' => 'Company', 'column' => array('homepage'))), |
|---|
| 65 |
)), |
|---|
| 66 |
))); |
|---|
| 67 |
} |
|---|
| 68 |
} |
|---|