public function setup()
 {
     parent::setup();
     $this->getWidgetSchema()->setFormFormatterName(sfConfig::get('app_rt_public_form_formatter_name', 'RtList'));
     // Variables
     $is_optional = !is_null($this->getOption('is_optional')) ? $this->getOption('is_optional') : true;
     $object = $this->getOption('object');
     $this->setWidget('type', new sfWidgetFormInputHidden());
     if (!$this->getOption('use_names', false)) {
         unset($this['first_name'], $this['last_name']);
     }
     unset($this['care_of'], $this['created_at'], $this['updated_at'], $this['model_id'], $this['longitude'], $this['latitude']);
     if (!$object) {
         throw new InvalidArgumentException('You must provide a parent object.');
     }
     $country = !is_null($this->getObject()->getCountry()) ? $this->getObject()->getCountry() : sfConfig::get('app_rt_region', '');
     $this->setWidget('country', new rtWidgetFormSelectCountry());
     $this->setDefault('country', $country);
     $this->setWidget('state', new rtWidgetFormSelectRegion(array('add_empty' => '--', 'country' => $country)));
     $this->setWidget('instructions', new sfWidgetFormInput());
     $this->setWidget('model', new sfWidgetFormInputHidden());
     $this->widgetSchema->moveField('country', 'before', 'state');
     $this->setValidators(array('id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)), 'type' => new sfValidatorChoice(array('choices' => array(0 => 'billing', 1 => 'shipping'), 'required' => false)), 'care_of' => new sfValidatorString(array('max_length' => 100, 'required' => false)), 'address_1' => new sfValidatorString(array('max_length' => 100, 'required' => false)), 'address_2' => new sfValidatorString(array('max_length' => 100, 'required' => false)), 'town' => new sfValidatorString(array('max_length' => 100, 'required' => false)), 'state' => new sfValidatorString(array('max_length' => 100, 'required' => false)), 'postcode' => new sfValidatorString(array('max_length' => 10, 'required' => false)), 'country' => new sfValidatorString(array('max_length' => 20, 'required' => false)), 'model' => new sfValidatorString(array('max_length' => 20, 'required' => false)), 'instructions' => new sfValidatorString(array('max_length' => 255, 'required' => false)), 'first_name' => new sfValidatorString(array('max_length' => 50, 'required' => false)), 'last_name' => new sfValidatorString(array('max_length' => 50, 'required' => false)), 'phone' => new sfValidatorString(array('max_length' => 20, 'required' => false))));
     $this->validatorSchema->setPostValidator(new rtAddressValidator(array('use_names' => $this->getOption('use_names', false), 'is_optional' => $is_optional)));
     $this->widgetSchema->setHelp('phone', 'Please include your area code.');
 }
 public function setup()
 {
     parent::setup();
     unset($this['model'], $this['model_id'], $this['type'], $this['created_at'], $this['updated_at']);
     $this->setWidget('type', new sfWidgetFormInputHidden());
     if (class_exists("sfWidgetFormI18nChoiceCountry")) {
         $this->widgetSchema["country"] = new sfWidgetFormI18nChoiceCountry(array('culture' => sfContext::getInstance()->getUser()->getCulture()));
     } else {
         $this->widgetSchema["country"] = new sfWidgetFormI18nSelectCountry(array('culture' => sfContext::getInstance()->getUser()->getCulture()));
     }
     $this->setDefault('country', sfConfig::get('app_rt_shop_default_country', 'AU'));
     $this->widgetSchema['care_of']->setLabel('Name');
     $this->setValidator('type', new sfValidatorChoice(array('choices' => array(0 => 'billing', 1 => 'shipping'), 'required' => true)));
     $this->setValidator('care_of', new sfValidatorString(array('max_length' => 255, 'required' => true), array('required' => 'Please provide a name')));
     $this->setValidator('address_1', new sfValidatorString(array('max_length' => 255, 'required' => true), array('required' => 'Please provide an address')));
     $this->setValidator('town', new sfValidatorString(array('max_length' => 255, 'required' => true), array('required' => 'Please provide a town')));
     $this->setValidator('state', new sfValidatorString(array('max_length' => 255, 'required' => true), array('required' => 'Please provide a state')));
     $this->setValidator('postcode', new sfValidatorInteger(array('required' => true), array('required' => 'Please provide a postcode')));
     $this->setValidator('phone', new sfValidatorString(array('max_length' => 20, 'required' => false)));
     $this->widgetSchema->setNameFormat('rt_address[%s]');
     $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
 }