Créer un compte ou loggez-vous pour pouvoir ajouter, commenter et noter les snippets.

Navigation

Tags relatifs

my Symfony Plugins

Plugins demos


My bookmarks

Vous pouvez commenter/noter en utilisant le compte anonymous (mot de passe: anonymous)
You can comment/rate using the anonymous account (password: anonymous).

Snippets taggés : "labels" Snippets taggés : "labels"

[symfony 1.1] Classe de formulaire typique - 716 view(s)

<?php
 
/**
 * Form to add a classified ad.
 * 
 * @author loic.vernet
 * @since  7 august 08
 *
 * @package    form
 */
 
class qbNewThreadForm extends qbThreadForm 
{
  // Default mask to create fields names
  public static $main_fields_name = 'qb_thread';
 
  // Default labels
  protected $labels = array(
 
    // Thread
    'title'         => 'Sujet',
    'category_id'   => 'Forum',
 
    // Contact form
    'qb_post'       => 'Post',
  );
 
  // Default fields to keep
  protected $fields_to_keep = array(
 
    // Thread
    'id',
    'category_id',
 
    // Post
    'qb_post',
  );
 
  // Liste of field that can't be modified by direct input values
  protected static $protected_fields = array(
  );
 
  /**
   * Configuration of form.
   */
  public function configure()
  {
    // Build widgets
    $this->setWidgetOptions();
 
    // Set wdigets
    $this->processWidgets();
 
    // Set validators    
    $this->processValidators();
 
    // Embed other forms
    $this->embedForms();
  }
 
  /**
   * Set generic options for widgets.
   * 
   * @author loic.vernet
   * @since
   */
  protected function setWidgetOptions()
  {
    // name format
    $this->widgetSchema->setNameFormat(self::$main_fields_name. '[%s]');
 
    // Set labels    
    $this->setLabels($this->labels);
 
    // Allow extra fields for all forms
    $this->allowExtraFields();
  }
 
  /**
   * set all widgets.
   * 
   * @author loic.vernet
   * @since
   */
  public function processWidgets()
  {
    $this->removeAllFieldsExcept($this->fields_to_keep);
 
    $this->widgetSchema['category_id'] = new sfWidgetFormPropelSelect(
      array(
        'model'     => 'qbCategory', 
        'add_empty' => false,
        //'criteria'  => ipAdBasePeer::getCategoriesCriteria()
    ));
 
    $this->widgetSchema['title'] = new sfWidgetFormInput();
  }  
 
  /**
   * Set all validators.
   * 
   * @author loic.vernet
   * @since 
   */
  public function processValidators()
  {
    $this->validatorSchema['category_id'] = new sfValidatorString(
        array('required' => true),
        array('required' => 'Veuillez choisir un forum')
    );
 
    $this->validatorSchema['title'] = new sfValidatorString(
        array('required' => true),
        array('required' => 'Veuillez choisir un titre pour le sujet')
    );
  }
 
  /**
   * Embed other forms to the current form.
   * 
   * @author loic.vernet 
   * @since 
   */
  protected function embedForms()
  {
  }
}
par COil le 2008-09-29, taggé : class  field  form  labels  symfony  validator  widget 
(1 commentaire)
Debug toolbar