Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony]Walidacja formularza
Lonas
post
Post #1





Grupa: Zarejestrowani
Postów: 576
Pomógł: 14
Dołączył: 9.11.2005

Ostrzeżenie: (20%)
X----


Jak się waliduje formularz ?

plik actions wyglada tak :

  1. <?php
  2. public function validateFormularz($request)
  3.  {
  4.    $name = $request->getParameter('name');
  5.  
  6.    // The name field is required
  7.    if (!$name)
  8.    {
  9.      $this->getRequest()->setError('name', 'The name field cannot be left blank');
  10.  
  11.      return false;
  12.    }
  13.  
  14.    // The name field must be a text entry between 2 and 100 characters
  15.    $myValidator = new sfStringValidator($this->getContext(), array(
  16.      'min'       => 2,
  17.      'min_error' => 'This name is too short (2 characters minimum)',
  18.      'max'       => 100,
  19.      'max_error' => 'This name is too long. (100 characters maximum)',
  20.    ));
  21.    if (!$myValidator->execute($name, $error))
  22.    {
  23.      return false;
  24.    }
  25.  
  26.    return true;
  27.  }
  28.  
  29.  
  30.  public function executeFormularz($request){
  31.  
  32.  
  33.  }  
  34.  
  35.   public function handleErrorFormularz()
  36.  {
  37.    // Prepare data for the template
  38.  
  39.    // Display the form
  40.    return sfView::SUCCESS;
  41.  }
  42. ?>


szablon tak :

  1. <?php use_helper('Validation') ?>
  2. <?php use_helper('Form') ?>
  3.  
  4. <?php echo form_tag('mymodule/formularz') ?>
  5.  <?php if ($sf_request->hasError('name')): ?>
  6.    <?php echo $sf_request->getError('name') ?> <br />
  7.  <?php endif; ?>
  8.  Name:    <?php echo input_tag('name') ?><br />
  9.  ...
  10.  <?php echo submit_tag() ?>
  11. </form>


po odpaleniu strony otrzymuje blad 505 - jak usune czesc odpowiedzialna za wyswietlenie komunikatu o bledzie
  1. <?php if ($sf_request->hasError('name')): ?>
  2.    <?php echo $sf_request->getError('name') ?> <br />
  3.  <?php endif; ?>

stronka sie wyswietla ale brak komunikatu..


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 10:00