Development

/branches/1.1/lib/helper/ValidationHelper.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/helper/ValidationHelper.php

Revision 7757, 1.8 kB (checked in by fabien, 7 years ago)

moved back helpers in lib/ as they won't be converted to classes for 1.1

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * ValidationHelper.
13  *
14  * @package    symfony
15  * @subpackage helper
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19
20 function form_has_error($param)
21 {
22   return sfContext::getInstance()->getRequest()->hasError($param);
23 }
24
25 function form_error($param, $options = array(), $catalogue = 'messages')
26 {
27   $param_for_sf = str_replace(array('[', ']'), array('{', '}'), $param);
28   $param = str_replace(array('{', '}'), array('[', ']'), $param);
29
30   $options = _parse_attributes($options);
31
32   $context = sfContext::getInstance();
33   $request = $context->getRequest();
34
35   $style = $request->hasError($param_for_sf) ? '' : 'display:none;';
36   $options['style'] = $style.(isset($options['style']) ? $options['style']:'');
37
38   if (!isset($options['class']))
39   {
40     $options['class'] = sfConfig::get('sf_validation_error_class', 'form_error');
41   }
42   if (!isset($options['id']))
43   {
44     $options['id'] = sfConfig::get('sf_validation_error_id_prefix', 'error_for_').get_id_from_name($param);
45   }
46
47   $prefix = sfConfig::get('sf_validation_error_prefix', '');
48   if (isset($options['prefix']))
49   {
50     $prefix = $options['prefix'];
51     unset($options['prefix']);
52   }
53
54   $suffix = sfConfig::get('sf_validation_error_suffix', '');
55   if (isset($options['suffix']))
56   {
57     $suffix = $options['suffix'];
58     unset($options['suffix']);
59   }
60
61   // translate error message if needed
62   $error = $request->getError($param_for_sf);
63   if (sfConfig::get('sf_i18n'))
64   {
65     $error = $context->getI18N()->__($error, null, $catalogue);
66   }
67
68   return content_tag('div', $prefix.$error.$suffix, $options)."\n";
69 }
70
Note: See TracBrowser for help on using the browser.