I create a very simple node type, added two fields of type textfield / integer with a range from 1 thru 100000

Obivously I expected the "create content" form to perform a validation on those two fields.
However I could just enter any textstring and just like a primitive atoi the results were zero (for the mandatory field) and a null (for the optional field)

Did I miss something? is this not yet implemented? planned?

thanks,
christoph

Comments

yched’s picture

Yes, actually the parsing of number fields remove any non numeric char (plus '-' and '.'). see http://drupal.org/node/108302
So if you enter 'azerty', you end up with '' (empty string).
But there is still

I think this is OK - but has a buggy side effect for required fields :
If you leave the field blank, you get a (Form API generated) 'required field' error
If you use invalid input ('azerty'), the field is not considered empty, then gets truncated to '', which gets stored as 0 in the db. And the field has a value that you did not actually enter, and which might not even be valid wrt min / max or allowed values settings.

yched’s picture

forget the incomplete 'But there is still' sentence above. Wrong edit.

yched’s picture

Title: Form validation missing for fields of type textfield / integer » Form validation missing for number fields
Component: content.module » number.module

http://www.drupal.org/node/116263 was marked duplicate.

nterbogt’s picture

There has to be a better way than just storing '' or a 0 in this case though. The current implementation is really really bad from a user point of view, and basically throws away all confidence in the system if they type 'something', save and see '0' in the results.

What are the general thoughts on how the CCK crew are going to deal with this. Could we just write a number validation function (one probably exists in PEAR) to rewrite all input to a general number format '123456789' and check that at the validate stage.

I understand that maintaining a function to do such a conversion would be a nightmare to maintain for internationalisation and the like, but anything is better than what current exists.

yched’s picture

Title: Form validation missing for number fields » Inconsistent validation for number fields
Priority: Normal » Critical

http://drupal.org/node/125754 (marked as a duplicate of this one) highlight another aspect of this :
- give you field the value 1000000, submit
- re-edit : widget gets pre-filled with 1e+06, which gets parsed as 106 on next submit.

Bumping the issue to critical. Having the values change in your back is not an option.

dopry’s picture

@yched: do you know if this is still an issue? or was it resolved else where?

yched’s picture

@dopry : nope, still an issue (most probably in D6 branch as well)

karens’s picture

Status: Active » Closed (won't fix)

The D5 version is no longer being supported. Sorry.

galaxor’s picture

Version: 5.x-1.3 » 6.x-2.9
Issue summary: View changes
Status: Closed (won't fix) » Active

This is still a problem in 6.x-2.9. At least, the thing where it silently changes text strings to zero. We noticed it when users were putting thousands-separators into their numbers, and the numbers would be saved as zero.

galaxor’s picture

Version: 6.x-2.9 » 5.x-1.3
Status: Active » Closed (won't fix)

Never mind, it was a patch I put into my code for a different purpose that messed up validation.