I have created a form and i am using validation on it but whenever i click on submit it not redirect and shows the same page.Even i have set the default values then also no help. please help me. Even i have check on varuious form no help.
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****
this is a class i which i am having my action class code.
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>-->
Your action class is not saving the form if it's valid. You should save and redirect if the form is valid:
If you need the form value on the next page, don't pass them in url, but flash instead: