you might think on creating diferent forms for each action, the
following code show how I do it in a DRY way:
<?php
### the "base" form:
<?php
class ElementoForm extends sfFormI18n
{
static public $opcoes =
array(''=>'','P'=>'Primeira','S'=>'Segunda');
public $configFields;
public function setup()
{
$fields = array();
$fields[0]['nuSeqElemento'] = new sfWidgetFormInputHidden();
$fields[0]['noElemento'] = new sfWidgetFormInput();
$fields[0]['dsElemento'] = new sfWidgetFormInput();
$fields[0]['nuSeqTipo'] = new
sfWidgetFormDoctrineSelect(array('model' =>
'Tipo','add_empty'=>true));
$fields[1]['nuSeqElemento'] = 'NUSEQELEMENTO';
$fields[1]['noElemento'] = 'Nome';
$fields[1]['dsElemento'] = 'Descrição';
$fields[1]['nuSeqTipo'] = 'Tipo';
$fields[2]['nuSeqElemento'] = new sfValidatorInteger(
array('required'=>false)
);
$fields[2]['noElemento'] = new sfValidatorString(
array(),
array('required'=>'O campo Nome é obrigatório')
);
$fields[2]['dsElemento'] = new sfValidatorString(
array('required'=>false)
);
$fields[2]['nuSeqTipo'] = new sfValidatorPass();
$this->configFields = $fields;
parent::setup();
}
function configure() {
$this->setWidgets($this->configFields[0]);
$this->widgetSchema->setLabels($this->configFields[1]);
$this->widgetSchema->setFormFormatterName('tableFnde');
$this->widgetSchema->setNameFormat('elemento[%s]');
$this->setValidators($this->configFields[2]);
parent::configure();
}
}
### the form without the "nuSeqTipo" field. Since I unset the
validator it works fine.
class ElementoEditForm extends ElementoForm
{
function configure() {
unset($this->configFields[2]['nuSeqTipo']); ################
<<<<< here I remove one field
parent::configure();
}
}
On 28 out, 21:02, beaulebens <[EMAIL PROTECTED]> wrote:
> I've now used the following in BaseFormPropel.class.php, which takes
> into account if aformfield was unset() during your configure()
>
> public function bind(array $taintedValues = null, array
> $taintedFiles = null) {
> $defs = $this->getDefaults();
> $defaults = array();
> foreach ($defs as $field=>$value) {
> if (in_array($field,
> array_keys($this->widgetSchema->getFields()))) {
>
> $defaults[$field] = $value;
> }
> }
> $taintedValues = array_merge($defaults, $taintedValues);
> parent::bind($taintedValues, $taintedFiles);
> }
>
> Still working to see if this will actually do what I want to do, but
> this seems to allow me to submit only a single value (or certain
> values) required in myform, while having all other fields "inherit"
> the values they currently have, based on the object theformis
> instantiated with.
>
> HTH
>
> Beau
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---