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.jsI’ve made the Profile 4 name mandatory:
$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:
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:
$profile4 = $superCage->post->getEscaped('user_profile4');
to this:
$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:
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:
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.