如果我的表单中的所有字段都填写正确,那么我可以保存表单,但如果某些字段未填写,则表示未显示验证消息。而绑定表单则可以使用isValid验证但不能在表单上显示消息.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>
答案 0 :(得分:0)
感谢你的回复。我的错误实际上我必须把
$this->setTemplate('newTask');
在 executeSubmit 操作中调用 processSchedulerForm 之后的这一行,这是用于显示该表单的模板,我可以显示验证消息。