Page 1 of 1

Custom Field Required Format

Posted: Wed Sep 23, 2009 8:51 pm
by Josh
Script URL: na
Version of script: .94
Hosting company: Internal
URL of phpinfo.php: na
URL of session_test.php: na
What terms did you try when SEARCHING for a solution: Date/custom/format

Write your message below:

Seems you've been doing a lot up updates with Hesk. Congrats to you Klemen. I've done some mild customizing with my small amount of PHP knowledge and I've got an open question to anyone.

This is the admin_main screen. The "Date Needed" is an optional custom field that is sortable. (see image)

My question is: Is there a way to prepopulate the field or require a particular format (MM\DD\YY) so that we can easily query by this custom date field. One of our users has a MySQL ODBC connector for MS Access and generates reports for ticket assignments, etc. As it stands I think it's just a text based field and queries do not produce a desired result.

We simply want users to be required to enter a standard date format since they like to ignore this and type things like "ASAP" when they submit a ticket.

Thanks.

-Josh

Image

Posted: Sat Sep 26, 2009 7:03 pm
by Klemen
Still using such an old version? Ow, upgrade it :wink:

Do you use any other custom fields? If yes what number is the "Date needed" one?

Posted: Mon Sep 28, 2009 3:25 am
by Josh
I know, it's time to upgrade. After customizing it's a little painful. :lol:

4 of the 5 custom fields are being used. The Date field is Custom Field #2 set to 8 characters currently.

Thanks,

josh

Posted: Mon Sep 28, 2009 6:06 pm
by Klemen
You could try changing adding something like this

Code: Select all

if ($k == 'custom2')
{
	echo '
	<tr>
	<td style="text-align:right" width="150">'.$v['name'].': '.$v['req'].'</td>
	<td width="80%"><input type="text" name="'.$k.'" size="40" maxlength="'.$v['maxlen'].'" value="'.date("m\\\d\\\y").'" /></td>
	</tr>
	';
	continue;
}
to index.php just below

Code: Select all

            else
            {
            	$k_value  = '';
            }
(twice in the file!).

Haven't tested it, but this should this should prepopulate the filed with correct date format.

Posted: Mon Sep 28, 2009 10:23 pm
by Josh
Thanks Klemen

My index page is a little old, so here's what I got. Seems to work so far even with the m/d/y change. Thanks for that.

I may tweek it just a bit as +7 days (if possible) might be a good default for expected completion which is what the field is used for in our case.

Thanks again.

Code: Select all


<!-- START CUSTOM BEFORE -->
<?php
/* custom fields BEFORE comments */
if ($hesk_settings['use_custom'] && $hesk_settings['custom_place']==1) {

    echo '<table border="0">';

    foreach ($hesk_settings['custom_fields'] as $k=>$v) {
        if ($v['use']) {
            if ($v['req']) {$v['req']='<font class="important">*</font>';}
            else {$v['req']='';}
            $k_value = stripslashes(hesk_input($_SESSION["c_$k"]));
			if ($k == 'custom2')
{
   echo '
   <tr>
   <td style="text-align:right" width="150">'.$v['name'].': '.$v['req'].'</td>
   <td width="80%"><input type="text" name="'.$k.'" size="40" maxlength="'.$v['maxlen'].'" value="'.date("m/d/y").'" /></td>
   </tr>
   ';
   continue;
}
            echo <<<EOC
    <tr>
    <td align="right" width="150">$v[name]: $v[req]</td>
    <td align="left" width="600"><input type="text" name="$k" size="40" maxlength="$v[maxlen]" value="$k_value"></td>
    </tr>

EOC;
        }
    }

    echo '</table> <hr>';
}
?>
<!-- END CUSTOM BEFORE -->