Validating DateTime

  • abarrow
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
12 years 3 months ago #24623 by abarrow
Validating DateTime was created by abarrow
I'm trying to add some code to fields.php to validate custom fields with DateTime.

Here's the code I'm using:
Code:
function _renderDateTimeValidation($row) { ?> /*load the field value into a variable*/ $test_date = form.<?php echo $row->name;?>.value; /*break it into an array*/ $test_arr = explode('/', $test_date); if (count($test_arr) == 3) { /*swapping around the array a little here, as checkdate expects mm/dd/yyyy */ if (checkdate($test_arr[1], $test_arr[0], $test_arr[2])) { return; } else { /*just use the same string as for when there is an empty field - I can just change the text */ alert("<?php echo JText::_($row->title).' '.JText::_('PF_IS_REQUIRED'); ?>"); form.<?php echo $row->name; ?>.focus(); return ; } <?php }

Unfortunately, it's not working - it just lets any text in as the date.

Any ideas?

Andy

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #24687 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Validating DateTime
Hi Andy

Did you mark the field as required when you create the custom field ? The code you wrote seems to be correct.

Tuan

Please Log in or Create an account to join the conversation.

  • abarrow
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
12 years 3 months ago #24745 by abarrow
Replied by abarrow on topic Re: Validating DateTime
I don't know what's happening with this. When I put in this code, clicking "Registration Confirmation" after filling out the form doesn't do anything - no confirmation page or anything. I'll see if I can find some error logs.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #24761 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Validating DateTime
Could you send me the link to the page so that I can have a quick look at it to see what's wrong and guide you fix it?

Tuan

Please Log in or Create an account to join the conversation.

  • abarrow
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
12 years 3 months ago #24765 by abarrow
Replied by abarrow on topic Re: Validating DateTime
Unfortunately we are going live tomorrow. I'll put in the fields.php that I've been working with for a few hours, but I'll have to take it out and go back to the old one after that.

www.wesmexregatta.org/register-to-race?t...istration&event_id=1


Andy

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #24767 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Validating DateTime
Hi Andy

I viewed source of the page and found out the issue with javascript syntax. Please upload the file fields.php here (you need to zip it before uploading) so that I can correct it for you.

Tuan

Please Log in or Create an account to join the conversation.

  • abarrow
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
12 years 3 months ago #24769 by abarrow
Replied by abarrow on topic Re: Validating DateTime
Wow, thanks Tuan!

File is attached.
Attachments:

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #24770 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Validating DateTime
Please get the updated file here and update it to your site. After that, please test it again. It should work as expected.

Tuan
Attachments:

Please Log in or Create an account to join the conversation.

  • abarrow
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
12 years 3 months ago #24771 by abarrow
Replied by abarrow on topic Re: Validating DateTime
Thank you so much. I see where I made the mistake now. Unfortunately I had the same result with this file.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #24772 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Re: Validating DateTime
There are more errors in the code and you will have to find out it yourself :

1. In javascript , there is no explode function (I think you getting this function from PHP), you will need to use split function www.w3schools.com/jsref/jsref_split.asp

2. I don't see anywhere in the file the javascript checkdate function defined, you will need to add it somewhere to the code.

Hope this give you some clues.

TUan

Please Log in or Create an account to join the conversation.

Moderators: Tuan Pham Ngoc