• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: how to validate date format?

how to validate date format? 12 years 1 month ago #16979

  • carlos0
  • carlos0's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
How do you put a date field, validate that a date be correct, but without using the calendar?
For example to introduce the date of birth.
The administrator has disabled public write access.

Re: how to validate date format? 12 years 1 month ago #16998

  • webcat-solutions
  • webcat-solutions's Avatar
  • OFFLINE
  • Junior Boarder
  • Dutch Joomla specialist
  • Posts: 29
  • Thank you received: 4
Hi Carlos,

I did this myself by making changes to a few source files and using that in combination with a textbox. The problem then is that when you install an update you need to put the changes back in place so it's a bit more work if you want to update rsform.
If that's no problem for you then let me know and I'll go and check the changes I made and post them.

Regards,
Chantal
p.s. It might also be possible by adding a php script in the php tab of the form to validate the input of the textfield. That way you would not have to make changes to the core file.
The administrator has disabled public write access.
The following user(s) said Thank You: carlos0

Re: how to validate date format? 12 years 1 month ago #17010

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
carlos0 wrote:
How do you put a date field, validate that a date be correct, but without using the calendar?
For example to introduce the date of birth.

It would be best to simply use a calendar field (in more recent versions you can select the year), or to use three drop-downs: year / month / day
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re: how to validate date format? 12 years 1 month ago #17039

  • carlos0
  • carlos0's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
webcat-solutions wrote:
Hi Carlos,

I did this myself by making changes to a few source files and using that in combination with a textbox. The problem then is that when you install an update you need to put the changes back in place so it's a bit more work if you want to update rsform.
If that's no problem for you then let me know and I'll go and check the changes I made and post them.

Regards,
Chantal
p.s. It might also be possible by adding a php script in the php tab of the form to validate the input of the textfield. That way you would not have to make changes to the core file.

You can serve me.
Tell me what is your solution and thank you very much.
The administrator has disabled public write access.

Re: how to validate date format? 12 years 1 month ago #17059

  • webcat-solutions
  • webcat-solutions's Avatar
  • OFFLINE
  • Junior Boarder
  • Dutch Joomla specialist
  • Posts: 29
  • Thank you received: 4
Hi Carlos,

here's what I did. The if statements could be cleaned up a little (feel free to ;-) and if you use this you will have to make modifications after each rsform update:

Backup all your rsform files before you start ;-).

Make changes to the following file with notepad or textpad:
joomlaroot/administrator/components/assets/js/script.js
Change line 868 from this:
if(elem.value == 'custom' || elem.value == 'numeric' || elem.value == 'alphanumeric' || elem.value == 'alpha' || elem.value == 'regex')
to this:
if(elem.value == 'custom' || elem.value == 'numeric' || elem.value == 'alphanumeric' || elem.value == 'alpha' || elem.value == 'regex' || elem.value == 'mydate')

Make changes to the following file with notepad or textpad:
joomlaroot/components/helpers/validation.php
Insert a new line between line 194 and 195 just before this:
}
?>
Add the following function in there
function mydate($param,$extra='dd-mm-yyyy', $data=null)
	{
		if(strlen($param) >= 6 && strlen($extra) == 10){
		// find separator. Remove all other characters from $extra
		$separator_only = str_replace(array('d','m','y'),'',$extra);
		$separator = $separator_only[0];
		// separator is first character
 
		if($separator && strlen($separator_only) == 2){
		// make regex
		$regexp = str_replace($separator,"\\" . $separator,$extra);
		$regexp = str_replace('mm','(0?[1-9]|1[0-2])',$regexp);
		$regexp = str_replace('dd','(0?[1-9]|[1-2][0-9]|3[0-1])',$regexp);
		$regexp = str_replace('yyyy','(19|20)?[0-9][0-9]',$regexp);
 
		if($regexp != $param && preg_match('/'.$regexp.'\\z/', $param)){
		// check date
		$arr=explode($separator,$param);
		$day=$arr[0];
		$month=$arr[1];
		$year=$arr[2];
		if(@checkdate($month,$day,$year))
		return true;
		}
		}
		}
	return false;
	}

Clean your joomla cache, clean your browser cache. (If the webserver uses output buffering you will have to wait till the server refreshes the output buffer before you will see the new validation method. In some horrible webhosting cases this takes hours).

Create a new text field and use the following settings:
General Tab:
Default value: dd-mm-yyyy (this will show the required date format in the textbox)
Validations Tab:
Required: Yes (I used Yes to make sure they enter something.)
Validation Extra: dd-mm-yyyy
Validation rule: mydate (select from list - if not there then there is still some caching or buffering going on)
Attributes Tab:
Size:20
Max size:10
Additional Attributes: dd-mm-yyyy

Good luck!
Chantal
The administrator has disabled public write access.
The following user(s) said Thank You: paolors1

Re: how to validate date format? 12 years 1 week ago #17257

  • paolors1
  • paolors1's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 1
tnx...this is exactly what i'm looking for!!!
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!