Andrzej Gis
Andrzej Gis

Reputation: 14306

Modify default forms in Symfony

I'd like to use forms generated by propel

( propel:generate-module --with-show --non-verbose-templates frontend user users )

but I'd like do modify them a little bit. e.q. I'd like to remove fields that are foreign keys. Is it possible, or do I have to create my own forms?

EDIT

in file: project_name/lib/form/form_file.class.php there is an empty class which derives from some base class. If put there something like this:

$this->setWidgets(array(
      'name'    => new sfWidgetFormInput()
));

All the default fields disappear and there is only this 'name' field in the form, which is not what I'm looking for.

Upvotes: 0

Views: 218

Answers (2)

Mike Purcell
Mike Purcell

Reputation: 19979

If you are using admin generator as you indicated, you can edit your forms via a generator.yml file. With this file you can do any number of things include set which widgets you want to appear, order of entry, actions, etc.

The generator.yml file is located in /apps/app_name/modules/module_name/config

You can read more about it in the symfony docs.

-- Edit --

If you are not using the generator.yml file, you can edit the form class directly, read this article relating to symfony forms for more info.

Example widget manipulation:

//-----
//Remove Unwanted
//-----
unset(
    $this['created_at'],
    $this['updated_at'],
    $this['ingredient_list'] //Will be embedded due to extra meta data
);
//-----

// Add a select menu using model to populate values
$this->widgetSchema['state_list'] = new sfWidgetFormPropelChoice(array('model' => 'State', 'multiple' => true, 'order_by' => array('name', 'asc')));

// Add matching validator
$this->validatorSchema['state_list'] = new sfValidatorPropelChoice(array('model' => 'State', 'column' => 'id', 'multiple' => true));

// I can also force widget presentation order
$this->getWidgetSchema()->moveField('country_list', sfWidgetFormSchema::AFTER, 'state_list');

// You can also add a callback function when the form is submitted
$this->validatorSchema->setPostValidator(
    new sfValidatorCallback(array('callback' => array($this, 'dupeCheck')))
);

Upvotes: 1

Vika
Vika

Reputation: 391

If you're not using admin generator, you can just edit the templates generated in the folder /app/modulename/templates/.

For example, modify the indexSuccess.php file contained in that folder to change the structure/info of the table created which by default will display all the info that exists in your DB table.

Upvotes: 0

Related Questions