Page 1 of 1

Turn Custom Field into Drop-Down list?

Posted: Wed Dec 12, 2007 4:25 am
by BigAnthony
Script URL:
Version of script: 0.94.1
Hosting company: server101
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: custom, drop-down

Write your message below:

My knowledge of PHP is very limited. I like the idea of the custom fields. Is there anyone there that has changed one to a drop-down list like a combo box in Microsoft Access? I undertsand I would have to adapt the SQL code and the field structure in the SQL table.

I would appreciate it if anyone had some code to share and reveal how they were able to do this?

Regards
Anthony

Posted: Wed Dec 12, 2007 9:51 am
by Klemen
I will try to include something in the next version, but I can't promise it. This has been asked before and I'm sure a lot of people are wondering how, so I will include basic instructions how to do it.

If you know HTML code and a little PHP you could get this working like this (may not be understandable if you don't know HTML):

1. in your browser open your page with the "Add a ticket" form (index.php?a=add) and view the HTML source code

2. you should see some code like this:

Code: Select all

<!-- START CUSTOM BEFORE -->
<table border="0">    <tr>
    <td align="right" width="150">Optional custom: </td>
    <td align="left" width="600"><input type="text" name="custom1" size="40" maxlength="255" value=""></td>
    </tr>
</table> <hr><!-- END CUSTOM BEFORE -->
(<!--START CUSTOM and <!-- END CUSTOM will be there, the code between depends on how many custom fields you use and for what). In the above example we have this HTML code to show a text input

Code: Select all

<input type="text" name="custom1" size="40" maxlength="255" value="">
3. now you can modify this text input HTML code as you wish, the only thing that matters is that name remains name="custom1" (and there is a limit of 255 chars in the database for each custom field value).

For example to change it to a drop-down list you could use

Code: Select all

<select name="custom1">
<option>First option</option>
<option>Second option</option>
<option>Third option</option>
</select>
4. Now what you need to do is edit index.php in a text editor, delete all PHP code between

Code: Select all

<!-- START CUSTOM BEFORE -->
and

Code: Select all

<!-- END CUSTOM BEFORE -->
and paste your edited HTML there. In the above case the code would be

Code: Select all

<!-- START CUSTOM BEFORE -->
<table border="0">    <tr>
    <td align="right" width="150">Optional custom: </td>
    <td align="left" width="600"><select name="custom1">
<option>First option</option>
<option>Second option</option>
<option>Third option</option>
</select></td>
    </tr>
</table> <hr><!-- END CUSTOM BEFORE -->

Note: if in your HTML code you have START CUSTOM AFTER and END CUSTOM AFTER delete PHP code between those two tags instead of START CUSTOM BEFORE and END CUSTOM BEFORE

This should work. It's far from practical and you would have to edit the code every time you enable/disable more custom fields, but for now it's the only work-around.

If you know HTML you should be able to make this work, if not I suggest hiring someone to do it for you.

Posted: Thu Dec 13, 2007 5:03 am
by BigAnthony
Thank you for the code.

I have it working with the drop-down lists.

Regards,
Anthony

Posted: Sat Dec 15, 2007 6:54 am
by BigAnthony
Sorry, I spoke too soon - it was working on the HTML code I had on my computer - but for the life of me I don't know what to do with the php on the server.

Oh well, I will have to wait for it to be implemented some day.

Thanks
Anthony

Posted: Sat Dec 15, 2007 12:20 pm
by Klemen
Did you finish step 4. in my previous post?

Posted: Sat Dec 15, 2007 10:53 pm
by BigAnthony
Klemen,

When you say index.php, I assume you mean I download the file from the server via ftp?

The code I get when I download it is:

<!-- 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"]));
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 -->

So, is this the file I have to change? When I load the page in the browser and view the source, all I see is the html code.

I appreciate you taking time to help me.

Anthony.

Posted: Sat Dec 15, 2007 11:17 pm
by BigAnthony
Klemen

I have it working on the website (this time for real :lol: )- I misread the line about "deleting all the php" code.

Thanks for your patience and help, I have appreciated it.

Anthony

Drop down for one custom field

Posted: Fri Aug 01, 2008 10:14 am
by paradis
How can i put Drop Down menu Just for One Of the Fields? For Example Field 5, This way you have told make a Drop down but not for a certain custom field

Integrate in custom fiel

Posted: Mon Dec 08, 2008 3:11 am
by maboo23
How can we integrate this drop down to be in the custom field?

I check data base it was not recorded.

Thanks

Posted: Mon Dec 08, 2008 7:02 am
by maboo23
I got it now.

Here is the sample working ===


<!-- 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"]));
echo <<<EOC

<tr>
<td align="right" width="150">Department: </td>
<td align="left" width="600"><select name="custom1">

<option>ALL Department</option>
<option>Dep 1</option>
<option>Dep 2</option>
<option>Dep 3</option>

</select></td>
</tr>


EOC;
}
}

echo '</table> <hr>';
}
?>

Posted: Mon Dec 08, 2008 4:27 pm
by Klemen
Just for your information: in the next version it will be easy to choose custom field type (text, radio, select, text box (textarea)).