requiring custom field with drop down box
Moderator: mkoch227
requiring custom field with drop down box
Script URL:
Version of script:
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:
Write your message below:
Hello everyone!
I added a custom drop down box for time spent, I have the "REQUIRED" YES box checked but, the thing with drop down boxes is they are already populated with the first entry... I set my first option to SELECT so poeple wouldn't be defaulting to the least amount of time possible. but they can still submit the ticket with the time spent field being populated with "SELECT"
how do i go about requiring them to fill this out before they can submit a ticket?
another question I had is how can I require someone to update a custom field and or write some notes when they set a case to "resolved" I looked through the default options and don't see it.
Version of script:
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:
Write your message below:
Hello everyone!
I added a custom drop down box for time spent, I have the "REQUIRED" YES box checked but, the thing with drop down boxes is they are already populated with the first entry... I set my first option to SELECT so poeple wouldn't be defaulting to the least amount of time possible. but they can still submit the ticket with the time spent field being populated with "SELECT"
how do i go about requiring them to fill this out before they can submit a ticket?
another question I had is how can I require someone to update a custom field and or write some notes when they set a case to "resolved" I looked through the default options and don't see it.
Re: requiring custom field with drop down box
Such modifications require a lot of coding/source code modifying and are unfortunately out of the scope of my support. Your best bet is to find a PHP programmer to help you.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: requiring custom field with drop down box
Here is how I did it.
This will show you how to make changes to the admin new ticket, I have not tested this on the customer interface, but it should work all the same.
First make sure you have your custom fields defined in Hesk Settings.
Next, I removed from admin/new_ticket.php
And
Your admin/new_ticket.php will no longer have custom fields on it, you will now need to code all your custom fields by hand.
For example, add the following to admin/new_ticket.php
Using the above code, you need to make sure you update you language file to include all your custom fields, Example:
Now you have your admin/new_ticket.php looking and working the way you want. You need to setup the requirement checks
Open admin/admin_submit_ticket.php & find
Below that paste
For every instance of the above line, you will be making that field "custom1" or "custom2".... a required field.
That should do it.
This will show you how to make changes to the admin new ticket, I have not tested this on the customer interface, but it should work all the same.
First make sure you have your custom fields defined in Hesk Settings.
Next, I removed from admin/new_ticket.php
Code: Select all
<!-- START CUSTOM BEFORE -->
<?php
/* custom fields BEFORE comments */
$print_table = 0;
foreach ($hesk_settings['custom_fields'] as $k=>$v)
{
if ($v['use'] && $v['place']==0)
{
if ($print_table == 0)
{
echo '<table border="0" width="100%">';
$print_table = 1;
}
# $v['req'] = $v['req'] ? '<font class="important">*</font>' : '';
# Staff doesn't need to fill in required custom fields
$v['req'] = '';
if ($v['type'] == 'checkbox')
{
$k_value = array();
if (isset($_SESSION["as_$k"]) && is_array($_SESSION["as_$k"]))
{
foreach ($_SESSION["as_$k"] as $myCB)
{
$k_value[] = stripslashes(hesk_input($myCB));
}
}
}
elseif (isset($_SESSION["as_$k"]))
{
$k_value = stripslashes(hesk_input($_SESSION["as_$k"]));
}
else
{
$k_value = '';
}
switch ($v['type'])
{
/* Radio box */
case 'radio':
echo '
<tr>
<td style="text-align:right" width="150" valign="top">'.$v['name'].': '.$v['req'].'</td>
<td width="80%">';
$options = explode('#HESK#',$v['value']);
$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';
foreach ($options as $option)
{
if (strlen($k_value) == 0 || $k_value == $option)
{
$k_value = $option;
$checked = 'checked="checked"';
}
else
{
$checked = '';
}
echo '<label><input type="radio" name="'.$k.'" value="'.$option.'" '.$checked.' '.$cls.' /> '.$option.'</label><br />';
}
echo '</td>
</tr>
';
break;
/* Select drop-down box */
case 'select':
$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';
echo '
<tr>
<td style="text-align:right" width="150">'.$v['name'].': '.$v['req'].'</td>
<td width="80%"><select name="'.$k.'" '.$cls.'>';
$options = explode('#HESK#',$v['value']);
foreach ($options as $option)
{
if (strlen($k_value) == 0 || $k_value == $option)
{
$k_value = $option;
$selected = 'selected="selected"';
}
else
{
$selected = '';
}
echo '<option '.$selected.'>'.$option.'</option>';
}
echo '</select></td>
</tr>
';
break;
/* Checkbox */
case 'checkbox':
echo '
<tr>
<td style="text-align:right" width="150" valign="top">'.$v['name'].': '.$v['req'].'</td>
<td width="80%">';
$options = explode('#HESK#',$v['value']);
$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';
foreach ($options as $option)
{
if (in_array($option,$k_value))
{
$checked = 'checked="checked"';
}
else
{
$checked = '';
}
echo '<label><input type="checkbox" name="'.$k.'[]" value="'.$option.'" '.$checked.' '.$cls.' /> '.$option.'</label><br />';
}
echo '</td>
</tr>
';
break;
/* Large text box */
case 'textarea':
$size = explode('#',$v['value']);
$size[0] = empty($size[0]) ? 5 : intval($size[0]);
$size[1] = empty($size[1]) ? 30 : intval($size[1]);
$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';
echo '
<tr>
<td style="text-align:right" width="150" valign="top">'.$v['name'].': '.$v['req'].'</td>
<td width="80%"><textarea name="'.$k.'" rows="'.$size[0].'" cols="'.$size[1].'" '.$cls.'>'.$k_value.'</textarea></td>
</tr>
';
break;
/* Default text input */
default:
if (strlen($k_value) != 0)
{
$v['value'] = $k_value;
}
$cls = in_array($k,$_SESSION['iserror']) ? ' class="isError" ' : '';
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="'.$v['value'].'" '.$cls.' /></td>
</tr>
';
}
}
}
/* If table was started we need to close it */
if ($print_table)
{
echo '</table> <hr />';
$print_table = 0;
}
?>
<!-- END CUSTOM BEFORE -->
Code: Select all
<!-- START CUSTOM AFTER -->
<?php
/* custom fields AFTER comments */
$print_table = 0;
foreach ($hesk_settings['custom_fields'] as $k=>$v)
{
if ($v['use'] && $v['place'])
{
if ($print_table == 0)
{
echo '<table border="0" width="100%">';
$print_table = 1;
}
For example, add the following to admin/new_ticket.php
Code: Select all
<table border="0" width="100%">
<tr>
<td style="text-align:right" width="150" >Site:<font class="important">*</font></td>
<td width="80%"><select name="custom1">
<option value=""/>Please Select..</option>
<option value="Value1"/>Value1</option>
<option value="Value2"/>Value2</option>
<option value="Value3"/>Value3</option>
<option value="Value4"/>Value4</option>
<option value="Value5"/>Value5</option>
</td>
</tr>
<tr>
<td style="text-align:right" width="150"><?php echo $hesklang['location']; ?>:<font class="important">*</font></td>
<td width="80%"><input type="text" name="custom2" size="40" maxlength="25"</td>
</tr>
<tr>
<td style="text-align:right" width="150"><?php echo $hesklang['locationdetail']; ?>:<font class="important">*</font></td>
<td width="80%"><input type="text" name="custom3" size="40" maxlength="25"/></td>
</tr>
<tr>
<td style="text-align:right" width="150"><?php echo $hesklang['building']; ?>:</td>
<td width="80%"><input type="text" name="custom4" size="40" maxlength="25" Autocomplete="off"/></td>
</tr>
</table>
<hr>
Code: Select all
$hesklang['building']='Building';
Open admin/admin_submit_ticket.php & find
Code: Select all
$tmpvar['message'] = hesk_input($_POST['message']) or $hesk_error_buffer['message']=$hesklang['enter_message'];
Code: Select all
$tmpvar['custom1'] = hesk_input($_POST['custom1']) or $hesk_error_buffer['custom1']="Please select a Site";
That should do it.
-Steve
Re: requiring custom field with drop down box
wow thanks man!, I will mess with this!... the other thing that I want to work on in the future is like requiring you to update said custom field when you mark it resolved or something... not terribly important but would be nice.
Re: requiring custom field with drop down box
as I'm testing this I'm seeing another default setting I don't like with Hesk..
The default category drop down... Yes it has a REQUIRED *, but it's not really required, because the drop down defaults to the first category instead of something that would cause it to fail...., and if the user forgets to drop down and select the correct category you're going to have a lot of tickets in the wrong category...
The default category drop down... Yes it has a REQUIRED *, but it's not really required, because the drop down defaults to the first category instead of something that would cause it to fail...., and if the user forgets to drop down and select the correct category you're going to have a lot of tickets in the wrong category...
Re: requiring custom field with drop down box
This one is rather easy to change - in index.php find this code
Just after this code add something like
Code: Select all
<select name="category" <?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> >
Code: Select all
<option value="">-- Please select --</option>
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: requiring custom field with drop down box
Thanks Klemen! I sent you a beer.
I'm messing with these required drop downs for now... and will add those lines you showed me too...
I'm messing with these required drop downs for now... and will add those lines you showed me too...
Re: requiring custom field with drop down box
Okay,
to force admins to select category in the /admin/new_ticket.php I added
to the line below this
to force admins to select category in the /admin/new_ticket.php I added
Code: Select all
<option value="">-- Please select --</option>
Code: Select all
<td width="80%"><select name="category" <?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
Last edited by dr_patso on Tue Jun 26, 2012 5:55 pm, edited 1 time in total.
Re: requiring custom field with drop down box
I haven't attempted to implement it fully on the test server, I messed with it enough to remove the custom fields...
I really want to get a hacky solution to display custom fields per the category selected as well as require some basic ones for all categories... also I want to require users to update a specific custom field drop down before they can resolve the case... I found a solution for hesk 2.2 on custom fields per category here and have been playing with it, don't think it will easily implement into hesk 2.3, the files that need to be edited seem different.
I really want to get a hacky solution to display custom fields per the category selected as well as require some basic ones for all categories... also I want to require users to update a specific custom field drop down before they can resolve the case... I found a solution for hesk 2.2 on custom fields per category here and have been playing with it, don't think it will easily implement into hesk 2.3, the files that need to be edited seem different.
Re: requiring custom field with drop down box
For custom fields based on category selected see this thread.
I also like the idea of forcing a user to update a field on resolution. I will start working on that with 2.4, let us know if you make any progress on that.
I also like the idea of forcing a user to update a field on resolution. I will start working on that with 2.4, let us know if you make any progress on that.
-Steve
Re: requiring custom field with drop down box
Oh sweet thanks Steve! Will this work in harmony with your script to require custom field values that are drop downs??? custom fields per category is important to me because each category/tool of support has different tasks and info involved.. I also wouldn't want to REQUIRE something like a SN if that particular category has nothing to do with devices...
The custom field I want to update upon resolution of the case is a time spent drop down, to avoid users inputting the wrong format it is a drop down, to avoid users forgetting to update the extra hour they spent on the case would make us look good too... FYI: I have no PHP knowledge just some good ctrl+f skills and logic.. using the find in files feature of notepad++, however I am motivated to learn PHP pretty awesomely right now.
The custom field I want to update upon resolution of the case is a time spent drop down, to avoid users inputting the wrong format it is a drop down, to avoid users forgetting to update the extra hour they spent on the case would make us look good too... FYI: I have no PHP knowledge just some good ctrl+f skills and logic.. using the find in files feature of notepad++, however I am motivated to learn PHP pretty awesomely right now.
Re: requiring custom field with drop down box
I haven't tested it but the two hacks should work together. Meaning, you can require the conditional drop down box to be selected using the method I described.
I started working on the mandatory custom field update, it looks like this could be fairly easy to pull off, ill keep you posted.
I also have very limited PHP knowledge, what I do know I learned off this board and a few google searches.
I started working on the mandatory custom field update, it looks like this could be fairly easy to pull off, ill keep you posted.
I also have very limited PHP knowledge, what I do know I learned off this board and a few google searches.
-Steve
Re: requiring custom field with drop down box
Hey Steve,
Is this right.. in your first reply to this thread you say to remove the start before section
what about the start after section do I get the whole thing or just how much you have in your code box??
Is this right.. in your first reply to this thread you say to remove the start before section
what about the start after section do I get the whole thing or just how much you have in your code box??
Code: Select all
<!-- START CUSTOM AFTER -->
<?php
/* custom fields AFTER comments */
$print_table = 0;
foreach ($hesk_settings['custom_fields'] as $k=>$v)
{
if ($v['use'] && $v['place'])
{
if ($print_table == 0)
{
echo '<table border="0" width="100%">';
$print_table = 1;
}
Re: requiring custom field with drop down box
I removed both the "Start custom before" & "Start custom after", its a little extra work because now you have to code all your input boxes, radio buttons, check boxes and drop down boxes by hand, but for my installation, this allowed me to install conditional boxes and set fields to required with more ease.
A little extra work in the beginning makes it easier to customize down the road I have found.
A little extra work in the beginning makes it easier to customize down the road I have found.
-Steve