Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

SmartyValidate Feature Req.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
tclineks
Smarty Rookie


Joined: 28 Apr 2005
Posts: 8
Location: KS

PostPosted: Thu Apr 28, 2005 10:35 pm    Post subject: SmartyValidate Feature Req. Reply with quote

It would be helpful to be able to set pre-error and post-error markup as to apply styling to the errors.

the extra
Code:
"<p class=\"validation_error\">" and "</p>"

isn't much but it's something that could be removed and some may have more complex markup around their errors.


Last edited by tclineks on Fri Apr 29, 2005 7:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 29, 2005 3:12 am    Post subject: Reply with quote

{validate ... assign="foo"}
{if $foo ne ""}blah{/if}
Back to top
View user's profile Send private message Visit poster's website
tclineks
Smarty Rookie


Joined: 28 Apr 2005
Posts: 8
Location: KS

PostPosted: Fri Apr 29, 2005 6:55 pm    Post subject: Reply with quote

Not clean enough! heh.
I just went ahead and added added this ..

line 436 of SmartyValidate.class.php inserted
[php:1:04743ffe9e] /**
* set pre and post error message markup
*
* @param string $pre the markup to apply before errors in this form
* @param string $post the markup to apply before errors in this form
* @param string $form the name of the form to apply pre and post error markup to
*/
function set_pre_post_markup($pre, $post, $form = 'default') {
$_SESSION['SmartyValidate'][$form]['pre'] = $pre;
$_SESSION['SmartyValidate'][$form]['post'] = $post;
}[/php:1:04743ffe9e]

replaced line 117 of function.validate.php
update: in SmartyValidate 2.5 the line is 122
[php:1:04743ffe9e] echo $_sess['pre'] . $_sess['validators'][$_validator_key]['message']. $_sess['post'];[/php:1:04743ffe9e]

so then i just need a
[php:1:04743ffe9e] SmartyValidate::set_pre_post_markup('<p class="error">','</p>');[/php:1:04743ffe9e]


Last edited by tclineks on Mon Jul 18, 2005 8:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 29, 2005 7:19 pm    Post subject: Reply with quote

If that works for you that's fine, although the markup should be controlled from the template (imho)

You could use a modifier:

{$error|prepost:'<p class="error">':'</p>'}
Back to top
View user's profile Send private message Visit poster's website
tclineks
Smarty Rookie


Joined: 28 Apr 2005
Posts: 8
Location: KS

PostPosted: Fri Apr 29, 2005 7:26 pm    Post subject: Reply with quote

mohrt wrote:

If that works for you that's fine, although the markup should be controlled from the template (imho)

Yeah, that's true.

I imagine pulling it out to function.validate_set_params or something would make more sense.

mohrt wrote:

You could use a modifier:

{$error|prepost:'<p class="error">':'</p>'}

True, though I do like the idea of just setting it once as they are virtually always going to be the same within a form.

maybe this?
[php:1:b52d6c89dc]
function smarty_function_validate_set_params($params, &$smarty) {

$_form = isset($params['form']) ? $params['form'] : 'default';
$_sess =& $_SESSION['SmartyValidate'][$_form];

if(!SmartyValidate::is_registered_form($_form)) {
trigger_error("SmartyValidate: [validate plugin] form '$_form' is not registered.");
return false;
}

if (!class_exists('SmartyValidate')) {
$smarty->trigger_error("validate: missing SmartyValidate class");
return;
}
if (!isset($_SESSION['SmartyValidate'])) {
$smarty->trigger_error("validate: SmartyValidate is not initialized, use connect() first");
return;
}

$_sess['pre'] = $params['pre'];
$_sess['post'] = $params['post'];
}


?>[/php:1:b52d6c89dc]
then this?

[php:1:b52d6c89dc]{validate_set_params pre="<p>" post="</p>"}
{validate ....}
[/php:1:b52d6c89dc]

should work for me.


Last edited by tclineks on Mon Jul 18, 2005 8:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Apr 29, 2005 8:04 pm    Post subject: Reply with quote

another option:

{config_load file="errors.conf"}
{validate ... message=#msg1#}

errors.conf:

msg1 = <p class="error">ERROR</p>

or, building off the last idea with a modifier:

{set_prepost pre='<p class="error">' post='</p>'}
{validate ... message="my message"|prepost}

Then that could be applied to anything.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP