Page 2 of 2
Re: requiring custom field with drop down box
Posted: Thu Jun 28, 2012 12:42 am
by dr_patso
dr_patso wrote: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??
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;
}
nevermind, i just removed the whole section.
Re: requiring custom field with drop down box
Posted: Thu Jun 28, 2012 11:20 pm
by dr_patso
if you want your custom field to highlight in red upon error like the original required fields
Code: Select all
<td style="text-align:right" width="150" >Time Spent:<font class="important">*</font></td>
<td width="80%"><select name="custom3" <?php if (in_array('custom3',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('custom3',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 6:42 am
by steve
Thats funny, after responding to your last inquiry, i started looking at my script, I noticed that I was missing that functionality.
Also, if your user has input text in all but one (or more) required feilds, and error is generated, but without the code below the data they entered will be lost and they will have to reenter it.
add this to the end of your string there
Code: Select all
<?php if (isset($_SESSION['as_custom3'])) {echo stripslashes(hesk_input($_SESSION['as_custom3']));} ?>
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 4:27 pm
by dr_patso
lol Steve, I was just coming here to say i noticed that custom fields dropped any data upon another error.
I think with that code you just posted it's perfect, minus having to code in new fields which anyone managing a tool like this should be able to do.
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 5:22 pm
by dr_patso
Hey steve where exactly do I put, not sure what you mean by the end of my string.
Code: Select all
<?php if (isset($_SESSION['as_custom3'])) {echo stripslashes(hesk_input($_SESSION['as_custom3']));} ?>
I've been plopping it all around my drop down and it doesn't seem to accomplish anything.
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 5:38 pm
by steve
Whenever I have questions about default HESK functionality, or where the code goes, I always consult the default Hesk 2.3 installation files. I run a separate installation of hesk that is just the basic install with no mods, that way if i remove of change something, I can always refer back to the base install.
Having said that, the code you need it this
Code: Select all
<tr>
<td style="text-align:right" width="150" valign="top"><?php echo $hesklang['message']; ?>: <font class="important">*</font></td>
<td width="80%"><textarea name="message" rows="12" cols="60" <?php if (in_array('message',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> ><?php if (isset($_SESSION['as_message'])) {echo stripslashes(hesk_input($_SESSION['as_message']));} ?></textarea><br /><br />
</td>
</tr>
Where "message" = your custom feild
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 5:46 pm
by dr_patso
this is how I nailed it for the custom fields with text input..
still working on the drop down.
Code: Select all
<tr>
<td style="text-align:right" width="150"><?php echo $hesklang['serialn']; ?>:</td>
<td width="80%"><input type="text" name="custom1" size="40" maxlength="25" value="<?php if (isset($_SESSION['as_custom1'])) {echo stripslashes(hesk_input($_SESSION['as_custom1']));} ?>"Autocomplete="off"/></td>
</tr>
<tr>
<td style="text-align:right" width="150"><?php echo $hesklang['contract_name']; ?>:</td>
<td width="80%"><input type="text" name="custom2" size="40" maxlength="25" value="<?php if (isset($_SESSION['as_custom2'])) {echo stripslashes(hesk_input($_SESSION['as_custom2']));} ?>" </td>
</tr>
the code added was
Code: Select all
value="<?php if (isset($_SESSION['as_custom2'])) {echo stripslashes(hesk_input($_SESSION['as_custom2']));} ?>"
obviously you change custom2 to the appropriate field you are working on.
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 6:54 pm
by dr_patso
I don't think
Code: Select all
<?php if (isset($_SESSION['as_custom1'])) {echo stripslashes(hesk_input($_SESSION['as_custom1']));} ?>
works for custom drop down menus.. just works for custom text fields
I think something like this would keep the custom drop down option selected if you error somewhere else.
Code: Select all
if (isset($_SESSION['as_category']) && $_SESSION['as_category'] == $row['id']) {$selected = ' selected="selected"';}
else {$selected = '';}
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 8:19 pm
by steve
I didn't test it on a drop down box.
Klemen may be able to provide an answer to that one.
Re: requiring custom field with drop down box
Posted: Fri Jun 29, 2012 10:19 pm
by steve
Ok, figured that one out.
To make this work with drop down boxes use something like this
Code: Select all
<option value="Option1" <?php if ($_SESSION['as_custom1']=="Option1") {echo 'selected="selected"';} ?>/>Option1</option>
So your drop down list will look something like this
Code: Select all
<td width="80%"><select name="custom1" <?php if (in_array('custom1',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('custom1',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?>>
<option value=""/>Please Select..</option>
<option value="Option1" <?php if ($_SESSION['as_custom1']=="Option1") {echo 'selected="selected"';} ?>/>Option1</option>
<option value="Option2" <?php if ($_SESSION['as_custom1']=="Option2") {echo 'selected="selected"';} ?>/>Option2</option>
<option value="Option3" <?php if ($_SESSION['as_custom1']=="Option3") {echo 'selected="selected"';} ?>/>Option3</option>
<option value="Option4" <?php if ($_SESSION['as_custom1']=="Option4") {echo 'selected="selected"';} ?>/>Option 4</option>
<option value="Option4" <?php if ($_SESSION['as_custom1']=="Option4") {echo 'selected="selected"';} ?>/>Option 4</option>
</td>
Re: requiring custom field with drop down box
Posted: Sun Jul 01, 2012 3:51 am
by dr_patso
works for me! thanks Steve! slightly off topic: now i move on to your conditional drop down boxes mod.. if i can get that to work all i've got left for it to be perfect is requiring to update the time spent custom field before ticket can be resolved
Re: requiring custom field with drop down box
Posted: Sun Jul 01, 2012 5:50 am
by steve
I have been playing with that one, I have been using a Javascript pop up box that prompts the user to enter some information before a ticket can be resolved.
Ill keep you posted on this. Im trying not to do to much more modification to Hesk, as I am waiting for 2.4 to come out so I can apply my efforts to that.
Re: requiring custom field with drop down box
Posted: Mon Jul 02, 2012 10:47 am
by dr_patso
EDIT: had a <tr> <hr /> formatting issue that didn't effect firfox but ruined the layout in IE.. I fixed.