Ask your Symfony questions! Pay money and get answers fast! (more info)

Trouble with formular Symfony


Hi experts,
i'm having a problem with getting data from a formular. But before i start explaining the issue, here are some information:


Timestampable: ~
bezeichnung: { type: string(50), notnull: true }
abschnitt_id: { type: integer, notnull: true }
blatt_nr: { type: integer, notnull: true}
typ: { type: string(1), notnull: true }
termin: { type: timestamp(25), notnull: false }
created_by: { type: integer, notnull: true }
updated_by: { type: integer, notnull: true }
Abschnitte: { onDelete: RESTRICT, local: abschnitt_id, foreign: id}

id: { type: integer, primary: true, notnull: true}
Blaetter: { onDelete: SET NULL, local: id, foreign: id }

As you can see on the attached image, i want to have radio-buttons for the type "Übungsblatt". After choosing one and pushing the submit-Button i get the following Error
<strong>500 | Internal Server Error | sfValidatorErrorSchema</strong>
bezeichnung [Required.] abschnitt_id [Required.] blatt_nr [Required.] typ [Required.] _csrf_token [Required.]

stack trace
at ()
in SF_ROOT_DIR/lib/vendor/symfony/lib/validator/sfValidatorSchema.class.php line 110 ...

$clean = array();

$unused = array_keys($this->fields);

$errorSchema = new sfValidatorErrorSchema($this);

// check that post_max_size has not been reached

if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > $this->getBytes(ini....)</blockquote>

I tried creating the formular the old-fashioned way, because i only need the radio-buttons for getting one Id (indexSuccess.php):
<h1>Blaetters List</h1>
<em><form action="<? url_for('blaetter/index'); ?>" method="post" ></em>
<table border="1">
<th>Blatt nr</th>
<th>Created at</th>
<th>Updated at</th>
<th>Created by</th>
<th>Updated by</th>
<?php foreach ($blaetters as $blaetter): ?>
<td><?php echo $abschnitte[$blaetter->getAbschnittId()].".".$blaetter->getBlattNr() ?></td>
<em><?php if ($blaetter->getTyp()==sfConfig::get('app_blaetter_uebung')):?>
<input type="radio" name="aktBlatt" value="<?php echo $blaetter->getId() ?>" />
<?php endif;?></em>
<td><?php echo $blaetter->getBezeichnung() ?></td>
<td><?php echo $abschnitte[$blaetter->getAbschnittId()] ?></td>
<td><?php echo $blaetter->getBlattNr() ?></td>
<td><?php echo sfConfig::get('app_blaetter_'.$blaetter->getTyp()) ?></td>
<?php $termin=$blaetter->getTermin();

echo DateTime::createFromFormat(sfConfig::get('app_datum_mysqlDatum'),$blaetter->getTermin())->format(sfConfig::get('app_datum_datumsFormat'));
}else{ echo sfConfig::get("app_datum_noDatum"); }
<?php echo link_to1('&Auml;ndern','blaetter/edit?id='.$blaetter->getId())?> |
<?php echo link_to1('L&ouml;schen','blaetter/del?id='.$blaetter->getId())?> | Benotung | Einzelergebnisse drucken
<?php if($blaetter->getCreatedAt()!=str_replace(";",":",sfConfig::get('app_datum_defaultDatum'))){
echo DateTime::createFromFormat(sfConfig::get('app_datum_mysqlDatum'),$blaetter->getCreatedAt())->format(sfConfig::get('app_datum_datumsFormat'));
}else{ echo sfConfig::get("app_datum_noDatum"); }
<?php if($blaetter->getUpdatedAt()!=str_replace(";",":",sfConfig::get('app_datum_defaultDatum'))){
echo DateTime::createFromFormat(sfConfig::get('app_datum_mysqlDatum'),$blaetter->getUpdatedAt())->format(sfConfig::get('app_datum_datumsFormat'));
}else{ echo sfConfig::get("app_datum_noDatum");}
<td><?php echo $dozenten[$blaetter->getCreatedBy()] ?></td>
<td><?php echo $dozenten[$blaetter->getUpdatedBy()] ?></td>
<?php endforeach; ?>
<input type="hidden" name="bezeichnung" value="" />
<input type="hidden" name="abschnitt_id" value="" />
<input type="hidden" name="blatt_nr" value="" />
<input type="hidden" name="typ" value="" />
<em><input type="submit" value=" Absenden ">


As you can see I already tried to give the "required-values" through hidden fields (uncommented), but that idea doesn't brought me any further.

I have searched for a function to disable the sfValidator only for this formular, but haven't found anything.

So do you know, what is wrong with my code?

Answers (1)


Wojciech Sznapka answers:

you can set in form class in configure method:

$this->validatorSchema['FIELD_NAME']->setOption('required', false);

or set sfValidatorPass for non-validating vields:

$this->validatorSchema['FIELD_NAME'] = new sfValidatorPass()

or simply you can unset unnecessary fields this way (still in form class configure method):


Martin Baudrechsel comments:

tried both:
<em>$this->validatorSchema['FIELD_NAME']->setOption('required', false);
class AktuellesBlattDefinitionForm extends sfForm{

public function configure(){

$this->validatorSchema['bezeichnung']->setOption('required', false);
$this->validatorSchema['abschnitt_id']->setOption('required', false);
$this->validatorSchema['blatt_nr']->setOption('required', false);
$this->validatorSchema['typ']->setOption('required', false);

<blockquote>Fatal error: Call to a member function setOption() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/bachelor/lib/form/doctrine/AktuellesBlattDefinitionForm.class.php on line 29</blockquote>

The Other Solution:
in configure():
$this->validatorSchema['bezeichnung'] = new sfValidatorPass();
$this->validatorSchema['abschnitt_id'] = new sfValidatorPass();
$this->validatorSchema['blatt_nr'] = new sfValidatorPass();
$this->validatorSchema['typ'] = new sfValidatorPass();

Again the Error mentioned above (sfValidatorErrorSchema)

Martin Baudrechsel comments:

unsetting gives me again the sfValidatorErrorSchema-Error

Wojciech Sznapka comments:

please provide code for blaetter/index action

Martin Baudrechsel comments:

maybe you need more information:

class blaetterActions extends sfActions
public function executeIndex(sfWebRequest $request)

$this->form=new AktuellesBlattDefinitionForm();

$blaetters = Doctrine::getTable('Blaetter')


/* $this->forward404Unless($request->isMethod(sfRequest::POST));
$this->forward404Unless(($blatt = Doctrine::getTable('blaetter')->findOneBy('id',$request->getParameter('id'))), sprintf('Objekt existiert nicht (%s).', $request->getParameter('id')));*/

$this->form= new AktuellesBlattDefinitionForm(); I am just doing to create an instance of the class and activating the things you said:
class AktuellesBlattDefinitionForm extends sfForm{

public function configure(){

/*$this->validatorSchema['bezeichnung']->setOption('required', false);
$this->validatorSchema['abschnitt_id']->setOption('required', false);
$this->validatorSchema['blatt_nr']->setOption('required', false);
$this->validatorSchema['typ']->setOption('required', false);*/

/*$this->validatorSchema['bezeichnung'] = new sfValidatorPass();
$this->validatorSchema['abschnitt_id'] = new sfValidatorPass();
$this->validatorSchema['blatt_nr'] = new sfValidatorPass();
$this->validatorSchema['typ'] = new sfValidatorPass();*/



Wojciech Sznapka comments:

how can it throw you any error while you aren't doing anything but displaying data in blaetter/index ? Where are you handling form?

Martin Baudrechsel comments:

that's why I'm really confused...

i'm displaying the data, as you can see above...

the error occourse after submitting the form

<form action="<? url_for('blaetter/index'); ?>" method="post" >

[---displaying data-----]

<input type="radio" name="aktBlatt" value="<?php echo $blaetter->getId() ?>" />

[---displaying data-----]

<input type="submit" value=" Absenden ">


Wojciech Sznapka comments:

haven't you modified routing? Maybe the form directs somewhere else...

Martin Baudrechsel comments:

that sucks... you are right... i already tried it before, but i did something wrong at this try...

Thank you so much!

Wojciech Sznapka comments:

so you messed up routing? :-)

Martin Baudrechsel comments:

yeah, i still have problems with this. the jobeet tutorial doesn't really helped me.
I choose you as winner, just want to make sure if that really is the reason.