modxcms / revolution

MODX Revolution - Content Management Framework
https://modx.com/
GNU General Public License v2.0
1.36k stars 529 forks source link

Can't enter date in "Date of birth" field in user save/edit form #11873

Closed gadgetto closed 5 years ago

gadgetto commented 10 years ago

The Date of birth field in create/edit user form is kind of broken. If you use the date picker or entering the value manually it always changes to this format: yyyy, mm-dd If you hit Save, the field error tells you: Please state the birthdate in mm/dd/yyyy format

If you try to enter the date manually you get this field error while typing: 10/05/ is not a valid date - it must be in the format Y, m-d

The manager_date_format in system settings is set to: Y, m-d (I think this was the default value)

This thing is trying to kidding me! :-) It's impossible to enter a value!

pixelchutes commented 10 years ago

I noticed that when running the user/update processor directly (via the MODX API), that passing in an existing User's Profile data as stored in the database would cause the same issue.

For example, the Date of Birth (dob field) is stored as unix_timestamp in the database. When I pass through a copy of the user's data (including profile fields) to user/update via $modx->runProcessor(), it would throw the same error you have listed as above.

To work around this, I had to convert date of birth into the specifed format first:

$properties['dob'] = date( 'm/d/Y', $properties['dob'] );

I would agree there appears to be an issue with the handling here. You should ideally be able to pass in dob as unix_timestamp, or any Date/Time format, and the processor handle it correctly, and manager_date_format only be used for UI / formatting purposes.

pixelchutes commented 10 years ago

It seems the mm/dd/yyyy suggested format is actually hard-coded into the 'user_err_not_specified_dob lexicon: https://github.com/modxcms/revolution/blob/master/core/lexicon/en/user.inc.php#L88-L90

Looking through the checkBirthDate() function in modUserValidation, nothing is jumping out to me.

https://github.com/modxcms/revolution/blob/master/core/model/modx/processors/security/user/_validation.php#L139

It seems to be leveraging strtotime() for conversion just fine here, so I wonder if there is something in the ExtJS that is not playing well with the Y, m-d format?

exside commented 10 years ago

What's in the POST fields when you try to save the userdata?

gadgetto commented 10 years ago

A little off topic but looking at the checkBirthDate() method here:

https://github.com/modxcms/revolution/blob/master/core/model/modx/processors/security/user/_validation.php#L143

It also seems you can't enter birth dates which are exactly on 1970-01-01 - as this date converts to 0 and 0 counts as empty()!

gadgetto commented 10 years ago

I have imported some users into the modUsers table which all have birth dates assigned as UNIX timestamps. Those users can't be edited/saved with the user/update page. If you click on Save it seems the changes are saved but the changes don't land in the database.

Removing the date of birth from user entry -> and editing/saving works as expected!

The MODX error log doesn't show any messages.

gadgetto commented 10 years ago

@exside the value of the dob field before submitting:

value: "2014, 08-06"
valueAsDate: null
valueAsNumber: NaN

The content of the headers and post fields:

Remote Address:188.40.126.44:80
Request URL:http://modx.bitego.com/connectors/index.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:877
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:modx_setup_language=en; _ga=GA1.2.1440066356.1402607997; PHPSESSID=tc8plcckfrqs076odqug94feh6
Host:modx.bitego.com
modAuth:modx53d213a466d5e0.74269303_153db55b139a352.20491834
Origin:http://modx.bitego.com
Powered-By:MODx
Referer:http://modx.bitego.com/manager/?a=security/user/update&id=9413
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
action:security/user/update
settings:{}
groups:[{"usergroup":9,"name":"Test","member":9413,"role":1,"rolename":"Member","primary_group":true,"rank":0,"menu":null}]
extended:{}
HTTP_MODAUTH:modx53d213a466d5e0.74269303_153db55b139a352.20491834
id:9413
username:user4
fullname:Bob Sponge
email:sponge.bob@gmx.at
phone:
mobilephone:
fax:
address:
city:
state:
zip:
country:
website:
dob:2014, 08-06
gender:0
newpassword:false
primary_group:9
active:1
sudo:0
blocked:0
blockeduntil:
blockedafter:
failedlogincount:0
class_key:modUser
comment:Imported: 2014-08-06 11:19:57
Test
passwordnotifymethod:s
passwordgenmethod:g
specifiedpassword:
confirmpassword:
namespace:core
area:
filter_key:Search by key......
ext-comp-1042:30
extended_name:
extended_value:
extended_id:
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:134
Content-Type:application/json; charset=UTF-8
Date:Wed, 06 Aug 2014 10:18:05 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=15, max=99
Pragma:no-cache
Server:Apache/2.2.16 (Debian)
Status:200 OK
Version:HTTP/1.1
X-Powered-By:PHP/5.3.3-7+squeeze19
gadgetto commented 10 years ago

Just changed the manager_date_format value in system settings to Y-m-d and now it seems to work. This value comes from a fresh 2.2.5 install. I don't know, where the strange `Y, m-d" date setting came from!?

Nevertheless there is a strange behavior with misleading error messages and I think the system should handle those "misconfigurations" - e.g. don't let save invalid date templates.

exside commented 10 years ago

This confirms my suspicion (which I had because for me it works) that it's dependent on manager_date_format...but you're right, it shouldn't fail...the question is, what to do if an admin specifies a date format, that cannot be parsed by strtotime?

Mark-H commented 10 years ago

Doesn't ext let you define a post value of sorts for date fields? Op 6 aug. 2014 15:59 schreef "luk" notifications@github.com:

This confirms my suspicion (which I had because for me it works) that it's dependent on manager_date_format...but you're right, it shouldn't fail...the question is, what to do if an admin specifies a date format, that cannot be parsed by strtotime?

— Reply to this email directly or view it on GitHub https://github.com/modxcms/revolution/issues/11873#issuecomment-51337855 .