Пример #1
0
 /**
  * Just to make sure every time a form is embedded, the 'remove' widgets
  * are added. They are needed in the deleting process
  */
 public function embedForm($name, sfForm $form, $decorator = null)
 {
     if ($form instanceof sfFormDoctrine) {
         $form->setWidget('remove', new sfWidgetFormInputHidden(array(), array('class' => 'remove')));
         $form->setValidator('remove', new sfValidatorPass());
     }
     parent::embedForm($name, $form, $decorator);
 }
Пример #2
0
 /**
  * Constructor.
  *
  * @param mixed  A object used to initialize default values
  * @param array  An array of options
  * @param string A CSRF secret (false to disable CSRF protection, null to use the global CSRF secret)
  *
  * @see sfForm
  */
 public function __construct($object = null, $options = array(), $CSRFSecret = null)
 {
     $class = $this->getModelName();
     if (!$object) {
         $this->object = new $class();
     } else {
         if (!$object instanceof $class) {
             throw new sfException(sprintf('The "%s" form only accepts a "%s" object.', get_class($this), $class));
         }
         $this->object = $object;
         $this->isNew = !$this->getObject()->exists();
     }
     parent::__construct(array(), $options, $CSRFSecret);
     $this->updateDefaultsFromObject();
 }
Пример #3
0
function url_for_form(sfFormObject $form, $routePrefix)
{
    $format = '%s/%s';
    if ('@' == $routePrefix[0]) {
        $format = '%s_%s';
        $routePrefix = substr($routePrefix, 1);
    }
    $uri = sprintf($format, $routePrefix, $form->getObject()->isNew() ? 'create' : 'update');
    return url_for($uri, $form->getObject());
}
Пример #4
0
 /**
  * Overrides sfForm::mergeForm() to also merge embedded forms
  * Allows autosave of merged collections
  *
  * @param  sfForm   $form      The sfForm instance to merge with current form
  *
  * @throws LogicException      If one of the form has already been bound
  */
 public function mergeForm(sfForm $form)
 {
     foreach ($form->getEmbeddedForms() as $name => $embeddedForm) {
         $this->embedForm($name, clone $embeddedForm);
     }
     parent::mergeForm($form);
 }
 /**
  * Renders a form tag suitable for the related Doctrine object.
  *
  * The method is automatically guessed based on the Doctrine object:
  *
  *  * if the object is new, the method is POST
  *  * if the object already exists, the method is PUT
  *
  * @param  string $url         The URL for the action
  * @param  array  $attributes  An array of HTML attributes
  *
  * @return string An HTML representation of the opening form tag
  *
  * @see sfForm
  */
 public function renderFormTag($url, array $attributes = array())
 {
     if (!isset($attributes['method'])) {
         $attributes['method'] = $this->isNew() ? 'post' : 'put';
     }
     return parent::renderFormTag($url, $attributes);
 }