I have dealing with that a couple of time before, I have use two ways (I
don´t know if they are the best).
The first, I know all I need, before request the form, for example based in
the user credential. In that case I made the changes at
"lib/form/doctrine/your-form.php"
public function configure()
{
//Some condition here example
$user = sfContext::getInstance()->getUser(); //the autenticated user
if (!$usuario->hasCredential('admin') or
!$usuario->hasCredential('Nacional') or
!$usuario->getGuardUser()->getIsSuperAdmin()):
{
$arrAreasId = array(0); $arrAreasNombres = array("Seleccione un
área");
//some code here to fill the $arrAreasId and $arrAreasNombres
arrays, the example is to big
//Some configuration here. example
$this->widgetSchema['Area'] = new
sfWidgetFormChoice(array('choices'=>array_combine($arrAreasId,
$arrAreasNombres),'expanded'=>false)); //I changed the control from a
textbox to a selectbox with my own content
//Or hide some fields
unset( $this['created_at'], $this['updated_at'],
$this['cal_rang_edad']
);
}
}
The second way: when I make the page request I still don´t know the
condition yet or I know just in this moment what I need (the conditional)
In this case in your form at:
apps/frontend/modules/mymodule/templates/_form.php
<form action="<?php echo url_for('personal/'.($form->getObject()->isNew() ?
'create' : 'update').(!$form->getObject()->isNew() ?
'?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php
$form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
// some required field here. example
<?php echo $form->renderHiddenFields() ?>
<table>
<?php echo $form['id']->renderRow() //also a required field?>
//some conditional here. example
<?
if($condition==1){
echo $form['field1']->renderRow()
}else{
echo $form['field2']->renderRow()
}
)?>
<table>
</form>
*Suppose the $condition var was defined in the accion.class.php file of
that module, example
public function executeNew(sfWebRequest $request)
{
$this->form = new dptoForm();
$condition = 1; // define your condition here. Make the steps you need
to get it.
}
and
public function executeEdit(sfWebRequest $request)
{
$this->forward404Unless($dpto =
Doctrine_Core::getTable('dpto')->find(array($request->getParameter('id'))),
sprintf('Object dpto does not exist (%s).', $request->getParameter('id')));
$this->form = new dptoForm($dpto);
$condition = 0; // define your condition here . Make the steps you need
to get it.
}
I hope this help.
Excuse my english please
2012/9/10 Javier Garcia <tirengar...@gmail.com>
> Hi,
> I need to create a form with dependant selects. The number of selects that
> will be shown are not always the same, because not all the levels have
> items. I mean, one item can have 3 levels below, and another item in the
> same level has 5 levels below.
> So, I was thinking in creating a form class, but since the number of
> fields is dynamic, how should be that form class?
> sf 1.4
> Javi
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
> You received this message because you are subscribed to the Google
> Groups "symfony1" group.
> To post to this group, send email to symfony1@googlegroups.com
> To unsubscribe from this group, send email to
> symfony1+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony1?hl=en
--
Me gustaría cambiar el mundo
Pero no encuentro el código fuente