我已经创建了一个表单,我正在使用验证,但每当我点击提交它不重定向并显示相同的页面。即使我已设置默认值,然后也没有帮助。 请帮我。 即使我检查了各种形式没有帮助。
registration form class
class registrationform extends sfForm {
//put your code here
protected static $option=array('Lab Technician','Lecturur','Assistant Professor','Professor','H.O.D');
public function configure() {
$this->setWidgets(array(
'first_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView'),array('default'=>'hello')),
'middle_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class' => 'textView')),
'last_Name'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')),
'age'=>new sfWidgetFormInputText(array('default'=>'hello'),array('class'=>'textView')),
));
$this->setValidators(array(
'first_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'middle_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'last_Name' => new sfValidatorString(array('required' => 'The message field is required.')),
'age' => new sfValidatorString(array('required' => 'The message field is required.')),
));
$this->widgetSchema->setNameFormat('contact[%s]');
}
****action.class.php****
这是一个我正在使用我的动作类代码的类。
public function executeIndex(sfWebRequest $request)
{
// $this->forward('default', 'module');
$this->registration_form = new registrationform();
if ($request->isMethod('POST'))
{
$this->registration_form->disableLocalCSRFProtection();
$this->registration_form->bind($request->getParameter('contact'));
if (!($this->registration_form->isValid()))
{
echo"\hiol";
$this->redirect('registration/thankyou?'.http_build_query($this->registration_form->getValues()));
}
}
indexsuccess
<?php echo stylesheet_tag('form');?>
<div class="page">
<div class="form" >
<form action="<?php echo url_for('registration/index') ?>" method="POST">
<div class="row" id="head">
REGISTRATION FORM
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['first_Name']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['first_Name']->render()?></div>
</div>
<div class="row">
<div ><?php echo $registration_form['first_Name']->renderError()?></div>
</div>
<div class="row">
<div class="columnLabel" ><?php echo $registration_form['middle_Name']->renderLabel()?></div>
<div class="columnView" ><?php echo $registration_form['middle_Name']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['last_Name']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['last_Name']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><?php echo $registration_form['age']->renderLabel()?></div>
<div class="columnView"><?php echo $registration_form['age']->render()?></div>
</div>
<div class="row">
<div class="columnLabel"><input class="button" type="submit" value="submit" name="submit"></div>
</div>
</form>
</div>
<!-- </div>
</div>
</div>
</div>
</div>-->
答案 0 :(得分:1)
如果表单有效,您的操作类不会保存该表单。如果表单有效,您应该保存并重定向:
if ($this->registration_form->isValid())
{
$this->registration_form->save();
$this->redirect('registration/thankyou');
}
如果您需要下一页上的表单值,请不要在网址中传递它们,而是闪存:
$this->getUser()->setFlash('registration_form', $this->registration_form->getValues());