Jak się waliduje formularz ?
plik actions wyglada tak :
<?php
public function validateFormularz($request)
{
$name = $request->getParameter('name');
// The name field is required
if (!$name)
{
$this->getRequest()->setError('name', 'The name field cannot be left blank');
return false;
}
// The name field must be a text entry between 2 and 100 characters
$myValidator = new sfStringValidator
($this->getContext(), array( 'min' => 2,
'min_error' => 'This name is too short (2 characters minimum)',
'max' => 100,
'max_error' => 'This name is too long. (100 characters maximum)',
));
if (!$myValidator->execute($name, $error))
{
return false;
}
return true;
}
public function executeFormularz($request){
}
public function handleErrorFormularz()
{
// Prepare data for the template
// Display the form
return sfView::SUCCESS;
}
?>
szablon tak :
<?php use_helper('Validation') ?>
<?php use_helper('Form') ?>
<?php echo form_tag
('mymodule/formularz') ?> <?php if ($sf_request->hasError('name')): ?>
<?php echo $sf_request->getError('name') ?> <br />
<?php endif; ?>
Name:
<?php echo input_tag
('name') ?><br />
...
<?php echo submit_tag
() ?> </form>
po odpaleniu strony otrzymuje blad 505 - jak usune czesc odpowiedzialna za wyswietlenie komunikatu o bledzie
<?php if ($sf_request->hasError('name')): ?>
<?php echo $sf_request->getError('name') ?> <br />
<?php endif; ?>
stronka sie wyswietla ale brak komunikatu..