how to autocomplete in custom field by jquery

Helpdesk for my helpdesk software

Moderator: mkoch227

Post Reply
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

how to autocomplete in custom field by jquery

Post by deserteagle369 »

Script URL:
Version of script: 2.3
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:

I want to do a auto complete in custom filed which search the history record to return the data to custom field.

I can do it for the email when user input name it will auto fill in email with js onchange code then call a empcheck.php file search in the mysql hesk_tickets and return the text.
sample code:

Code: Select all

<td width="80%"><input type="text" name="name" id="name" onchange = "empcheck();" size="40" maxlength="30" value="<?php if (isset($_SESSION['c_name'])) {echo stripslashes(hesk_input($_SESSION['c_name']));} ?>" <?php if (in_array('name',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> /></td>
my problem are:

1.
but the custom filed is generate by a foreach and switch code, I don't know how to do this, for example when people type in custom7 field (I put department info here) it will auto complete by jquery like demo in below:

http://www.jqueryrain.com/?jpzxv5Id

2.
I have to keep two copy of empcheck.php for it work for both user and admin, one under hesk folder and one under \hesk\admin folder, I tried add the path in the \admin\new_ticket.php when call php file but it can't work.
Eagle
Life is a journey.
Klemen
Site Admin
Posts: 10147
Joined: Fri Feb 11, 2005 4:04 pm

Re: how to autocomplete in custom field by jquery

Post by Klemen »

If you are trying to add that to filed 'custom1' you would find

Code: Select all

	foreach ($hesk_settings['custom_fields'] as $k=>$v)
	{
and add something like this below:

Code: Select all

if ($k == 'custom1')
{
// Print the field HTML code and anything you want here

// This line will tell PHP to skip the rest of code for 'custom1' and start with next one
continue;
}
The second problem is most likely related to paths - try using full root server paths instead of relative ones.
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
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: how to autocomplete in custom field by jquery

Post by deserteagle369 »

Finally I get the auto complete work for custom filed 7 by use jquery-1.4.2.js from devmanuals.com, but after I submit the ticket I found the custom filed 7 is empty. How to solve it?

thx.
Eagle
Life is a journey.
deserteagle369
Posts: 94
Joined: Wed Feb 29, 2012 2:00 am

Re: how to autocomplete in custom field by jquery

Post by deserteagle369 »

I solved it by myself.

for user
index.php
add function after <head>, pserieis the id of the input area, pseriesearch.php will search the table in mysql.

Code: Select all

<meta charset="UTF-8" />
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript">
$().ready(function() {
	$("#pserie").autocomplete("pseriesearch.php", {
		width: 350,
		matchContains: true,
		//autoFill:false,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
</script>
then build the input area, seperate it from foreach loop, after

Code: Select all

	foreach ($hesk_settings['custom_fields'] as $k=>$v)
	{
add

Code: Select all

" if ($k == 'custom2')
 {
 // Print the field HTML code and anything you want here
 ?>

 <tr>
 <td style=""text-align:right"" width=""150"">Product Series:</td>
 <td width=""80%""><input type=""text"" name=""pserie"" id=""pserie"" size=""50"" maxlength=""150"" value=""<?php if (isset($_SESSION['custom2'])) {echo stripslashes(hesk_input($_SESSION['custom2']));} ?>"" <?php if (in_array('custom2',$_SESSION['iserror'])) {echo ' class=""isError"" ';} ?> /><input type=""reset"" value=""Clear"">
 </td>
 </tr>

 <?php

 // This line will tell PHP to skip the rest of code for 'custom2' and start with next one
 continue;
 }"
in submit_ticket.php

after

Code: Select all

/* Custom fields */
foreach ($hesk_settings['custom_fields'] as $k=>$v)
{
add

Code: Select all

	if ($k == 'custom2')
	{
	// custom2(pserie) start

	if ($v['req'])
        {
        	$tmpvar[$k]=hesk_makeURL(nl2br(hesk_input($_POST['pserie'])));
            if (!strlen($tmpvar[$k]))
            {
            	$hesk_error_buffer[$k]=$hesklang['fill_all'].': '.$v['name'];
            }
        }
		else
        {
        	$tmpvar[$k]=hesk_makeURL(nl2br(hesk_input($_POST['pserie'])));
        }
		$_SESSION["c_$k"]=$_POST['pserie'];

	// custom2(pserie) end
	continue;
	}
for admin, you need modify new_ticket.php and admin_submit_ticket.php correspondly.

cheer.
Eagle
Life is a journey.
Post Reply