Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: utroda - helmikuu 07, 2014, 01:46:04 IP

Otsikko: Custom Validation on Additional Profile Inputs
Kirjoitti: utroda - helmikuu 07, 2014, 01:46:04 IP
I created a new additional profile input, that just an input that can take a text string, but I need the ability to make sure users can only update this field once in 24 hours. I see that i can write regex for string validation but where would i go about writing a validation method to make sure an input can only be updated within x amount of hours?
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: margarett - helmikuu 07, 2014, 01:51:42 IP
That should be something very hard to achieve...

The way the fields are stored is not compatible with any kind of "time-based" checking... I can't really imagine an easy way to do it without substantially change the current codebase...
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: utroda - helmikuu 07, 2014, 01:57:20 IP
Well, can't i just like loop the array of custom fields on profile save, find the one that matches, then check last updated time, if not return the user to the profile with an error?

I'm sure how the form data is saved currently.
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: margarett - helmikuu 07, 2014, 02:07:45 IP
How it works, you can find explanation here:
http://www.simplemachines.org/community/index.php?topic=518203.msg3666696#msg3666696

And there you can see that there is no real way to get the last modified time...
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: utroda - helmikuu 07, 2014, 02:25:30 IP
what if i created a new table that stored that information and checked against that?
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: margarett - helmikuu 07, 2014, 02:36:09 IP
Yup, that's a thought.
You need to basically duplicate the "themes" table structure, with an extra column to store the modified time, because it has no single "ID" like others

Lainaus käyttäjältä: margarett - helmikuu 07, 2014, 01:51:42 IP
That should be something very hard to achieve...
See what I mean? :P
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: utroda - helmikuu 07, 2014, 02:41:27 IP
You would think by default that you would have a last updated time for anything that a user can change.
Otsikko: Re: Custom Validation on Additional Profile Inputs
Kirjoitti: Arantor - helmikuu 07, 2014, 10:38:33 IP
You would think that storing that for the hundreds of possible values that a user can update, it would get very inefficient to store the last-updated time as well.