Turn Custom Field into Drop-Down list?

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
BigAnthony
Posts: 5
Joined: Wed Dec 12, 2007 4:09 am

Turn Custom Field into Drop-Down list?

Post 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
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Post 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.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image 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
BigAnthony
Posts: 5
Joined: Wed Dec 12, 2007 4:09 am

Post by BigAnthony »

Thank you for the code.

I have it working with the drop-down lists.

Regards,
Anthony
BigAnthony
Posts: 5
Joined: Wed Dec 12, 2007 4:09 am

Post 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
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Did you finish step 4. in my previous post?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image 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
BigAnthony
Posts: 5
Joined: Wed Dec 12, 2007 4:09 am

Post 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.
BigAnthony
Posts: 5
Joined: Wed Dec 12, 2007 4:09 am

Post 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
paradis
Posts: 2
Joined: Fri Jul 25, 2008 1:30 pm

Drop down for one custom field

Post 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
maboo23
Posts: 3
Joined: Thu Nov 27, 2008 2:41 am

Integrate in custom fiel

Post by maboo23 »

How can we integrate this drop down to be in the custom field?

I check data base it was not recorded.

Thanks
maboo23
Posts: 3
Joined: Thu Nov 27, 2008 2:41 am

Post 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>';
}
?>
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Post 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)).
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image 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
Post Reply