Development

/branches/1.0/lib/helper/ValidationHelper.php

You must first sign up to be able to contribute.

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

Revision 1553, 1.7 kB (checked in by fabien, 8 years ago)

fixed html 'id' attribute for form_error() helper (closes #670)

  • 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   $request = sfContext::getInstance()->getRequest();
33
34   $style = $request->hasError($param_for_sf) ? '' : 'display:none;';
35   $options['style'] = $style.(isset($options['style']) ? $options['style']:'');
36
37   if (!isset($options['class']))
38   {
39     $options['class'] = sfConfig::get('sf_validation_error_class', 'form_error');
40   }
41   if (!isset($options['id']))
42   {
43     $options['id'] = sfConfig::get('sf_validation_error_id_prefix', 'error_for_').get_id_from_name($param);
44   }
45
46   $prefix = sfConfig::get('sf_validation_error_prefix', '');
47   if (isset($options['prefix']))
48   {
49     $prefix = $options['prefix'];
50     unset($options['prefix']);
51   }
52
53   $suffix = sfConfig::get('sf_validation_error_suffix', '');
54   if (isset($options['suffix']))
55   {
56     $suffix = $options['suffix'];
57     unset($options['suffix']);
58   }
59
60   $error = $request->getError($param_for_sf, $catalogue);
61
62   return content_tag('div', $prefix.$error.$suffix, $options)."\n";
63 }
64
Note: See TracBrowser for help on using the browser.