This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » development » Feature requests » sfValidatorString: option to trim value
sfValidatorString: option to trim value [message #102895] Wed, 21 July 2010 19:39 Go to next message
stebleton  is currently offline stebleton
Messages: 3
Registered: July 2010
Location: San Francisco, CA
Junior Member
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:
  • 'leading'
  • 'trailing'
  • 'both'
  • boolean false, indicating no trimming

Cheers,
Scott
Re: sfValidatorString: option to trim value [message #102910 is a reply to message #102895 ] Thu, 22 July 2010 07:15 Go to previous messageGo to next message
cokker  is currently offline cokker
Messages: 582
Registered: January 2007
Location: Germany
Faithful Member
afaik there exists an option for trim. Perhaps have a look at the source or search the forum.

greets
Sven
Re: sfValidatorString: option to trim value [message #102964 is a reply to message #102910 ] Fri, 23 July 2010 00:25 Go to previous messageGo to next message
stebleton  is currently offline stebleton
Messages: 3
Registered: July 2010
Location: San Francisco, CA
Junior Member
cokker wrote on Wed, 21 July 2010 22:15

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...
Re: sfValidatorString: option to trim value [message #102975 is a reply to message #102895 ] Fri, 23 July 2010 07:07 Go to previous messageGo to next message
djones  is currently offline djones
Messages: 62
Registered: November 2007
Member
Actually, sfValidatorString DOES have a 'trim' option by default as it extends sfValidatorBase which has 'required', 'trim' and 'empty' options.
Re: sfValidatorString: option to trim value [message #102976 is a reply to message #102975 ] Fri, 23 July 2010 07:20 Go to previous message
stebleton  is currently offline stebleton
Messages: 3
Registered: July 2010
Location: San Francisco, CA
Junior Member
Oh cool, I didn't even think to look at sfValidatorBase. Thanks djones Smile
Previous Topic:Integration symfony with shindig
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software