| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|