如果我的表单中的所有字段都正确填写,则可以保存表单,但如果某些字段未填写,则不会显示验证消息。绑定表单时,它可以使用 isValid 进行验证,但不会在 form.plz 上显示消息帮助我?这是我的基本形式
abstract class BaseTgSchedulerForm extends BaseFormDoctrine{
public function setup()
{
$this->setWidgets(array(
'id' => new sfWidgetFormInputHidden(),
'emp_number'=> new sfWidgetFormInput(array()),
'task_name'=> new sfWidgetFormInputText(array()),
'curr_execution_date' => new ohrmWidgetDatePicker(array('label'=>'ExecutionDate'),
array('id'=>'curr_execution_date'),array('class'=>'formDateInput')),
'curr_remind_date' => new ohrmWidgetDatePicker(array('label'=>'Remind Date'), array('id'=>'curr_remind_date'),array('class'=>'formDateInput')),
'status_id' => new sfWidgetFormInputHidden(),
));
$this->setValidators(array(
'id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)),
'emp_number' => new sfValidatorInteger(array('required'=>true)),
'task_name' => new sfValidatorString(array('max_length' => 255)),
'curr_execution_date' => new ohrmDateValidator(array('required'=>true) ),
'curr_remind_date' => new ohrmDateValidator(array('required'=>true) ),
'status_id' => new sfValidatorInteger(array('required'=>false)),
));
$this->setDefault('status_id', 1);
$this->widgetSchema->setNameFormat('tg_scheduler[%s]');
$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
$this->setupInheritance();
parent::setup();
}
public function getModelName()
{
return 'TgScheduler';
}
}
这是我提交后的操作
public function executeSubmit(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod(sfRequest::POST));
$this->form = new TgSchedulerForm();
$this->processSchedulerForm($request, $this->form);
}
protected function processSchedulerForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()));
if ($form->isValid())
{
$tg_scheduler = $form->save();
}
}
渲染表单相关代码
<form action="<?php echo url_for('scheduler/'.($form->getObject()->isNew() ? 'submit' : 'update').(!$form->getObject()->isNew() ? '?task_id='.$form->getObject()->getTaskId() : '')) ?>" 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; ?>
<table class="task-form">
<tfoot>
<tr>
<td colspan="1"></td><td>
<!-- <a href="<?php //echo url_for('scheduler/index') ?>">Back to list</a>
<?php //if (!$form->getObject()->isNew()): ?>
<?php //echo link_to('Delete', 'scheduler/delete?task_id='.$form->getObject()->getTaskId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
<?php //endif; ?></td><td>-->
<input type="submit" class="submit" value="Save" />
</td>
</tr>
</tfoot>
<tbody>
<?php echo $form ?>
</tbody>