This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

sfValidatorString: option to trim value

Requests for new symfony features.

sfValidatorString: option to trim value

by stebleton » Wed Jul 21, 2010 7:39 pm

Hello,

It would be useful to have an option in sfValidatorString to automatically trim leading and/or trailing whitespace from the value upon submission. This option would be performed prior to applying the min_length and max_length options.

Default would be false, meaning no trimming is performed. Acceptable values would be:
<ul type="disc">
<li>'leading'
<li>'trailing'
<li>'both'
<li>boolean false, indicating no trimming
</ul>
Cheers,
Scott
stebleton
Junior Member
 
Posts: 3
Joined: Wed Jul 21, 2010 7:32 pm
Location: San Francisco, CA

Re: sfValidatorString: option to trim value

by cokker » Thu Jul 22, 2010 7:15 am

afaik there exists an option for trim. Perhaps have a look at the source or search the forum.

greets
Sven
cokker
Faithful Member
 
Posts: 591
Joined: Mon Jan 15, 2007 10:43 am
Location: Germany

Re: sfValidatorString: option to trim value

by stebleton » Fri Jul 23, 2010 12:25 am

cokker wrote: afaik there exists an option for trim. Perhaps have a look at the source or search the forum.


I always search the forum and the source before asking anything. :)~ :-)~ :smile:

The only options added by sfValidatorString are min_length, max_length, and empty_value. I may just extend sfValidatorString to include this option.

On further reflection, a validator isn't really the ideal place for this kind of uniform modification--it's not validation, but a form of pre-processing--but adding it as an option to sfValidatorString gives the convenience of not having to modify the values myself prior to handing them off for validation.

I've yet to look into Symfony 2.0, so I can't speak to the form-processing features it is set to contain, but this points to the potential utility of a framework for processing form values prior to validation. Other possible string pre-processing might include converting everything to lowercase or uppercase, stripping various character classes ([non]alphanumeric, punctuation, etc.) or even regular expression matches, character escaping...
stebleton
Junior Member
 
Posts: 3
Joined: Wed Jul 21, 2010 7:32 pm
Location: San Francisco, CA

Re: sfValidatorString: option to trim value

by djones » Fri Jul 23, 2010 7:07 am

Actually, sfValidatorString DOES have a 'trim' option by default as it extends sfValidatorBase which has 'required', 'trim' and 'empty' options.
djones
Member
 
Posts: 62
Joined: Sun Nov 11, 2007 7:00 pm

Re: sfValidatorString: option to trim value

by stebleton » Fri Jul 23, 2010 7:20 am

Oh cool, I didn't even think to look at sfValidatorBase. Thanks djones :)~ :-)~ :smile:
stebleton
Junior Member
 
Posts: 3
Joined: Wed Jul 21, 2010 7:32 pm
Location: San Francisco, CA