Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Custom field to store date and ability to check the date format  (Read 3119 times)

0 Members and 1 Guest are viewing this topic.

jimmym

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Custom field to store date and ability to check the date format
« on: November 30, 2011, 03:32:37 am »

I’ve configured Custom field (Profile 4 name) for entering birthdate.  I’ve modified the register.php and register.js according to several forum postings http://forum.coppermine-gallery.net/index.php/topic,37086.0.html, http://forum.coppermine-gallery.net/index.php/topic,70390.msg344548.html#msg344548 and others...

I’m now stucked cos I’m not able to code logic for date format check in the register.js

I’ve made the Profile 4 name mandatory:
Code: [Select]
$form_data = array(
        array('label', $lang_register_php['required_info']),
        array('input', 'username', $icon_array['username'] . $lang_register_php['username'], 25),
        !empty($CONFIG['global_registration_pw']) ? array('password', 'global_registration_pw', $icon_array['password'] . $lang_register_php['global_registration_pw'], 25) : '',
        array('password', 'password', $icon_array['password'] . $lang_register_php['password']),
        array('password', 'password_verification', $icon_array['password'] . $lang_register_php['password_again']),
        array('input', 'email', $icon_array['email'] . $lang_register_php['email'], 255),
        !empty($CONFIG['user_profile1_name']) ? array('input', 'user_profile1', $icon_array['blank'] . $CONFIG['user_profile1_name'], 255) : '',
        !empty($CONFIG['user_profile2_name']) ? array('input', 'user_profile2', $icon_array['blank'] . $CONFIG['user_profile2_name'], 255) : '',
        !empty($CONFIG['user_profile3_name']) ? array('input', 'user_profile3', $icon_array['blank'] . $CONFIG['user_profile3_name'], 255) : '',
        !empty($CONFIG['user_profile4_name']) ? array('input', 'user_profile4', $icon_array['blank'] . $CONFIG['user_profile4_name'], 255) : '',
        array('label', $lang_register_php['optional_info'])
    );
    $optional_data = 0;

I’ve put in the error messages if the field is blank or entered with the incorrect format.  This is called by the register.js:
Code: [Select]
if ($element[1] == 'user_profile4') {
                $warning1 = '<div id="user_profile4_warning1" class="cpg_message_validation formFieldWarning" style="display:none;">';
                $warning1 .= 'The ' . $CONFIG['user_profile4_name'] . ' mustn\'t be empty!';
                $warning1 .= '</div>';
                $warning2 = '<div id="user_profile4_warning2" class="cpg_message_validation formFieldWarning" style="display:none;">';
                $warning2 .= 'The ' . $CONFIG['user_profile4_name'] . ' must be dd.mm.yyyy format! eg. 09.06.2006';
                $warning2 .= '</div>';
            }


I've changed this:
Code: [Select]
$profile4 = $superCage->post->getEscaped('user_profile4');
to this:
Code: [Select]
$profile4 = trim(get_post_var('user_profile4'));

I've added this to check the entered date.  This is in the function check_user_info(&$error) in the registered.php:
Code: [Select]
if ($profile4 != ' ') {
    $date_format = 'd.m.Y';
    $my_input = trim($profile4);
    $time = strtotime($my_input);
    $is_valid = date($date_format, $time) == $my_input;

    if ($is_valid == '0') {
      $error .= '<li style="list-style-image:url(images/icons/stop.png)">Value \'' . $CONFIG['user_profile4_name'] . '\' must be in dd.mm.yyyy format! eg. 09.06.2006</li>';
      $error .= $is_valid;
     }
    }

In the registered.js I’ve added this but not working fully yet:
Code: [Select]
  if($('#user_profile4').val() == '') {
        $('#user_profile4_warning1').show();
        errors++;
    } else {
          if ($('#user_profile4').val().search(/^(0?[1-9])/(0?[1-9]/((19|20)\\d\\d)$/) == -1) {
            $('#user_profile4_warning2').show();
            errors++;
        }
    }

Here’s where I need help from the Java guru.  Could you help to provide the correct code to check the date format?

Thanks in advance.

Logged

jimmym

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Custom field to store date and ability to check the date format
« Reply #1 on: November 30, 2011, 03:42:05 am »

I've added this to check the entered date.  This is in the function check_user_info(&$error) in the registered.php:
Code: [Select]
if ($profile4 != ' ') {
    $date_format = 'd.m.Y';
    $my_input = trim($profile4);
    $time = strtotime($my_input);
    $is_valid = date($date_format, $time) == $my_input;

    if ($is_valid == '0') {
      $error .= '<li style="list-style-image:url(images/icons/stop.png)">Value \'' . $CONFIG['user_profile4_name'] . '\' must be in dd.mm.yyyy format! eg. 09.06.2006</li>';
      $error .= $is_valid;
     }
    }

In the registered.js I’ve added this but not working fully yet:
Code: [Select]
  if($('#user_profile4').val() == '') {
        $('#user_profile4_warning1').show();
        errors++;
    } else {
          if ($('#user_profile4').val().search(/^(0?[1-9])/(0?[1-9]/((19|20)\\d\\d)$/) == -1) {
            $('#user_profile4_warning2').show();
            errors++;
        }
    }

How to code the java logic for checking for date format d.m.Y  which I have in the registered.php?
Code: [Select]
if ($profile4 != ' ') {
    $date_format = 'd.m.Y';
    $my_input = trim($profile4);
    $time = strtotime($my_input);
    $is_valid = date($date_format, $time) == $my_input;

    if ($is_valid == '0') {
      $error .= '<li style="list-style-image:url(images/icons/stop.png)">Value \'' . $CONFIG['user_profile4_name'] . '\' must be in dd.mm.yyyy format! eg. 09.06.2006</li>';
      $error .= $is_valid;
     }
    }
Logged

jimmym

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Custom field to store date and ability to check the date format
« Reply #2 on: December 01, 2011, 06:52:18 pm »

I've resolved my problem.  I basically change the regular expression to check the date format dd.mm.yyyy

As originally posted:
Code: [Select]
if($('#user_profile4').val() == '') {
        $('#user_profile4_warning1').show();
        errors++;
    } else {
          if ($('#user_profile4').val().search(/^(0?[1-9])/(0?[1-9]/((19|20)\\d\\d)$/) == -1) {
            $('#user_profile4_warning2').show();
            errors++;
        }
    }

Resolved by this:
Code: [Select]
if($('#user_profile4').val() == '') {
        $('#user_profile4_warning1').show();
        errors++;
    } else {
          if ($('#user_profile4').val().search(/^(((0[1-9]|[12]\d|3[01])[.](0[13578]|1[02])[.](([2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)[.](0[13456789]|1[012])[.](([2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])[.]02[.](([2-9]\d)\d{2}))|(29[.]02[.](([2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00))))$/) == -1) {
            $('#user_profile4_warning2').show();
            errors++;
        }
    }

I'm pretty happy about it. It work exactly as what I wanted.
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 19 queries.