This forum is archived. Posts are preserved for historical reference. For current help, join us on Discord.

Validate Class

In UserSpice 4.3 and Below · Started by marceloatmartins on 2017-08-18 8:14 pm · 13661 views · 6 replies

Hi Everybody,

Did someone make an implementation for validate fields kind "DATE" in Validate Class ?

How can I do it?

Thanks


No. And we probably need to overhaul that class. I keep running into things it doesn't do. I do my date validation in html.
<input type="date"

Here is the validation rule that I use. Feel free to adjust the date format to something else.
case 'valid_date':
$d = DateTime::createFromFormat('Y-m-d', $value);
if(($d && $d->format('Y-m-d') == $value)) $valid = true;
else $valid = false;
if ($valid != true) {
$this->addError(["{$display} must be a date with a format of YYYY-MM-DD.", $item]);
}
break;
Awesome! Thanks for this!
I have this and a few others posted in the modifications forum, in one of faguss' threads.

https://userspice.com/forums/topic/validation-class-improvements-2/

They were during your busy months so you may have missed them!
Wow, really Thanks for help me

I do some tests with "<input type="date", but this doesn't work under Mozilla Firefox and I don't like use javascript a lot for validate fields in form I think that best validations are in back end like Validate Class.

Thank you for all.


Right. Yeah. JS is not the best way to do it. The newest validate class is in the 4.3 alpha and was just updated a few minutes ago.

https://github.com/mudmin/UserSpice43dev/blob/master/users/classes/Validate.php