Conditional Dropdown Boxes

Everything related to Hesk - helpdesk software

Moderator: mkoch227

plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

hm. I still can't get the script to post the sub-cats. I've got my 2 root cats "I need help with..." and "I have a request regarding...". Selecting either does nothing.

Sorry to paste the entire code but I fear I may have messed up because I've played around with it so much at this point.

Code: Select all


<?php
/*******************************************************************************
*  Title: Help Desk Software HESK
*  Version: 2.3 from 15th September 2011
*  Author: Klemen Stirn
*  Website: http://www.hesk.com
********************************************************************************
*  COPYRIGHT AND TRADEMARK NOTICE
*  Copyright 2005-2011 Klemen Stirn. All Rights Reserved.
*  HESK is a registered trademark of Klemen Stirn.

*  The HESK may be used and modified free of charge by anyone
*  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
*  By using this code you agree to indemnify Klemen Stirn from any
*  liability that might arise from it's use.

*  Selling the code for this program, in part or full, without prior
*  written consent is expressly forbidden.

*  Using this code, in part or full, to create derivate work,
*  new scripts or products is expressly forbidden. Obtain permission
*  before redistributing this software over the Internet or in
*  any other medium. In all cases copyright and header must remain intact.
*  This Copyright is in full effect in any country that has International
*  Trade Agreements with the United States of America or
*  with the European Union.

*  Removing any of the copyright notices without purchasing a license
*  is expressly forbidden. To remove HESK copyright notice you must purchase
*  a license for this script. For more information on how to obtain
*  a license please visit the page below:
*  https://www.hesk.com/buy.php
*******************************************************************************/

define('IN_SCRIPT',1);
define('HESK_PATH','../');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_session_start();
hesk_dbConnect();
hesk_isLoggedIn();

/* Varibles for coloring the fields in case of errors */
if (!isset($_SESSION['iserror']))
{
	$_SESSION['iserror'] = array();
}

if (!isset($_SESSION['isnotice']))
{
	$_SESSION['isnotice'] = array();
}

/* List of users */
$admins = array();
$sql = "SELECT `id`,`name`,`isadmin`,`categories`,`heskprivileges` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."users` ORDER BY `id` ASC";
$result = hesk_dbQuery($sql);
while ($row=hesk_dbFetchAssoc($result))
{
	/* Is this an administrator? */
	if ($row['isadmin'])
    {
	    $admins[$row['id']]=$row['name'];
	    continue;
    }

	/* Not admin, is user allowed to view tickets? */
	if (strpos($row['heskprivileges'], 'can_view_tickets') !== false)
	{
		$admins[$row['id']]=$row['name'];
		continue;
	}
}

/* Print header */
require_once(HESK_PATH . 'inc/header.inc.php');

/* Print admin navigation */
require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');

?>

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

<?php
/* This will handle error, success and notice messages */
hesk_handle_messages();
?>

<p class="smaller">&nbsp;<a href="admin_main.php" class="smaller"><?php echo $hesk_settings['hesk_title']; ?></a> > <?php echo $hesklang['nti2']; ?></p>

<p><?php echo $hesklang['nti3']; ?><br />&nbsp;</p>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td width="7" height="7"><img src="../img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
	<td class="roundcornerstop"></td>
	<td><img src="../img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
</tr>
<tr>
	<td class="roundcornersleft">&nbsp;</td>
	<td>

	<h3 align="center"><?php echo $hesklang['nti2']; ?></h3>

	<p align="center"><?php echo $hesklang['req_marked_with']; ?> <font class="important">*</font></p>

    <!-- START FORM -->

	<form method="post" action="admin_submit_ticket.php" name="form1" enctype="multipart/form-data">

	<!-- Contact info -->
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['name']; ?>: <font class="important">*</font></td>
	<td width="80%"><input type="text" name="name" size="40" maxlength="30" value="<?php if (isset($_SESSION['as_name'])) {echo stripslashes(hesk_input($_SESSION['as_name']));} ?>" <?php if (in_array('name',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> /></td>
	</tr>
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['email']; ?>: <font class="important">*</font></td>
	<td width="80%"><input type="text" name="email" size="40" maxlength="50" value="<?php if (isset($_SESSION['as_email'])) {echo stripslashes(hesk_input($_SESSION['as_email']));} ?>" <?php if (in_array('email',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('email',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> /></td>
	</tr>
	</table>

	<hr />

	<!-- Department and priority -->
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['category']; ?>: <font class="important">*</font></td>
	<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" ';} ?> >
	<?php
	if (!empty($_GET['catid']))
	{
		$_SESSION['as_category'] = intval($_GET['catid']);
	}

	$sql = 'SELECT * FROM `'.hesk_dbEscape($hesk_settings['db_pfix']).'categories` ORDER BY `cat_order` ASC';
	$result = hesk_dbQuery($sql);
	while ($row=hesk_dbFetchAssoc($result))
	{
	    if (isset($_SESSION['as_category']) && $_SESSION['as_category'] == $row['id']) {$selected = ' selected="selected"';}
	    else {$selected = '';}
	    echo '<option value="'.$row['id'].'"'.$selected.'>'.$row['name'].'</option>';
	}

	?>
	</select></td>
	</tr>
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['priority']; ?>: <font class="important">*</font></td>
	<td width="80%"><select name="priority" <?php if (in_array('priority',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> >
	<option value="3" <?php if(isset($_SESSION['as_priority']) && $_SESSION['as_priority']==3) {echo 'selected="selected"';} ?>><?php echo $hesklang['low']; ?></option>
	<option value="2" <?php if(isset($_SESSION['as_priority']) && $_SESSION['as_priority']==2) {echo 'selected="selected"';} ?>><?php echo $hesklang['medium']; ?></option>
	<option value="1" <?php if(isset($_SESSION['as_priority']) && $_SESSION['as_priority']==1) {echo 'selected="selected"';} ?>><?php echo $hesklang['high']; ?></option>
	<option value="0" <?php if(isset($_SESSION['as_priority']) && $_SESSION['as_priority']==0) {echo 'selected="selected"';} ?>><?php echo $hesklang['critical']; ?></option>
	</select></td>
	</tr>
	</table>

	<hr />
<script language="javascript" type="text/javascript">

    function dropdownlist(listindex)

    {

    document.form1.subcategory.options.length = 0;

    switch (listindex)

    {

    case "1" :

    document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

    document.form1.subcategory.options[1]=new Option("Air-Conditioners/Coolers","Air-Conditioners/Coolers");

    document.form1.subcategory.options[2]=new Option("Audio/Video","Audio/Video");

    document.form1.subcategory.options[3]=new Option("Beddings","Beddings");

    document.form1.subcategory.options[4]=new Option("Camera","Camera");

    document.form1.subcategory.options[5]=new Option("Cell Phones","Cell Phones");

    break;

    case "9" :

    document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

    document.form1.subcategory.options[1]=new Option("Colleges","Colleges");

    document.form1.subcategory.options[2]=new Option("Institutes","Institutes");

    document.form1.subcategory.options[3]=new Option("Schools","Schools");

    document.form1.subcategory.options[4]=new Option("Tuitions","Tuitions");

    document.form1.subcategory.options[5]=new Option("Universities","Universities");

    break;

    /*case "7" :

    document.form1.subcategory.options[0]=new Option("Select Sub-Category","");

    document.form1.subcategory.options[1]=new Option("College Books","College Books");

    document.form1.subcategory.options[2]=new Option("Engineering","Engineering");

    document.form1.subcategory.options[3]=new Option("Magazines","Magazines");

    document.form1.subcategory.options[4]=new Option("Medicine","Medicine");

    document.form1.subcategory.options[5]=new Option("References","References");

    break;*/
    }
    return true;
    }
    </script>
    </head>
    <title>Dynamic Drop Down List</title>
    <body>
    <form id="form1" name="form1" method="post" action="submitform1.asp" >
    <table width="100%" border="0" >
    <tr>
    <td style="text-align:right" width="150">Sub Category:
    </td>
    <td width="80%"><script type="text/javascript" language="JavaScript">
    document.write('<select name="subcategory"><option value="">Select Sub-Category</option></select>')
    </script>
    <noscript><select name="subcategory" id="subcategory" >
    <option value="">Select Sub-Category</option>
    </select>
    </noscript></td>
    </tr>
    </table>
    </form>

	<!-- 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 -->

	<!-- ticket info -->
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150"><?php echo $hesklang['subject']; ?>: <font class="important">*</font></td>
	<td width="80%"><input type="text" name="subject" size="40" maxlength="40" value="<?php if (isset($_SESSION['as_subject'])) {echo stripslashes(hesk_input($_SESSION['as_subject']));} ?>" <?php if (in_array('subject',$_SESSION['iserror'])) {echo ' class="isError" ';} ?> /></td>
	</tr>
	<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>
	</table>

	<hr />

	<!-- 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;
	        }

			# $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 AFTER -->

	<?php
	/* attachments */
	if ($hesk_settings['attachments']['use']) {

	?>
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150" valign="top"><?php echo $hesklang['attachments']; ?>:</td>
	<td width="80%" valign="top">
	<?php
	for ($i=1;$i<=$hesk_settings['attachments']['max_number'];$i++)
    {
    	$cls = ($i == 1 && in_array('attachments',$_SESSION['iserror'])) ? ' class="isError" ' : '';
		echo '<input type="file" name="attachment['.$i.']" size="50" '.$cls.' /><br />';
	}
	?>
	<?php echo$hesklang['accepted_types']; ?>: <?php echo '*'.implode(', *', $hesk_settings['attachments']['allowed_types']); ?><br />
	<?php echo $hesklang['max_file_size']; ?>: <?php echo $hesk_settings['attachments']['max_size']; ?> Kb
	(<?php echo sprintf("%01.2f",($hesk_settings['attachments']['max_size']/1024)); ?> Mb)
	</td>
	</tr>
	</table>

	<hr />
	<?php
	}
	?>

    <!-- Admin options -->
	<table border="0" width="100%">
	<tr>
	<td style="text-align:right" width="150" valign="top"><b><?php echo $hesklang['addop']; ?>:</b></td>
	<td width="80%">
    	<label><input type="checkbox" name="notify" value="1" <?php echo (!isset($_SESSION['as_notify']) || !empty($_SESSION['as_notify'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['seno']; ?></label><br />
        <label><input type="checkbox" name="show" value="1" <?php echo (!isset($_SESSION['as_show']) || !empty($_SESSION['as_show'])) ? 'checked="checked"' : ''; ?> /> <?php echo $hesklang['otas']; ?></label><br />
        <hr />
    </td>
	</tr>

	<?php
	if (hesk_checkPermission('can_assign_others',0))
	{
    ?>
	<tr>
	<td style="text-align:right" width="150" valign="top"><b><?php echo $hesklang['owner']; ?>:</b></td>
	<td width="80%">
		<?php echo $hesklang['asst2']; ?> <select name="owner" <?php if (in_array('owner',$_SESSION['iserror'])) {echo ' class="isError" ';} ?>>
		<option value="-1"> > <?php echo $hesklang['unas']; ?> < </option>
		<?php

		if ($hesk_settings['autoassign'])
		{
			echo '<option value="-2"> > ' . $hesklang['aass'] . ' < </option>';
		}

        $owner = isset($_SESSION['as_owner']) ? intval($_SESSION['as_owner']) : 0;

		foreach ($admins as $k=>$v)
		{
			if ($k == $owner)
			{
				echo '<option value="'.$k.'" selected="selected">'.$v.'</option>';
			}
            else
			{
				echo '<option value="'.$k.'">'.$v.'</option>';
			}

		}
		?>
		</select>
    </td>
	</tr>
    <?php
	}
	elseif (hesk_checkPermission('can_assign_self',0))
	{
    $checked = (!isset($_SESSION['as_owner']) || !empty($_SESSION['as_owner'])) ? 'checked="checked"' : '';
	?>
	<tr>
	<td style="text-align:right" width="150" valign="top"><b><?php echo $hesklang['owner']; ?>:</b></td>
	<td width="80%">
    	<label><input type="checkbox" name="assing_to_self" value="1" <?php echo $checked; ?> /> <?php echo $hesklang['asss2']; ?></label><br />
    </td>
	</tr>
    <?php
	}
	?>
	</table>

    <hr />

	<!-- Submit -->
	<p align="center"><input type="hidden" name="token" value="<?php hesk_token_echo(); ?>" />
    <input type="submit" value="<?php echo $hesklang['sub_ticket']; ?>" class="orangebutton"  onmouseover="hesk_btn(this,'orangebuttonover');" onmouseout="hesk_btn(this,'orangebutton');" /></p>

	</form>

    <!-- END FORM -->

	</td>
	<td class="roundcornersright">&nbsp;</td>
</tr>
<tr>
	<td><img src="../img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
	<td class="roundcornersbottom"></td>
	<td width="7" height="7"><img src="../img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
</tr>
</table>
<?php

hesk_cleanSessionVars('iserror');
hesk_cleanSessionVars('isnotice');

require_once(HESK_PATH . 'inc/footer.inc.php');
exit();
?>
steve
Posts: 147
Joined: Tue Mar 27, 2012 9:32 pm

Re: Conditional Dropdown Boxes

Post by steve »

Im glad you posted the entire admin/new_ticket.php, this allowed me to run the page on my test server.

The only issue you have is that you were not calling the Javascript, you have everything else coded fine and in the right place.

Change this

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" ';} ?> >
to this

Code: Select all

<td width="80%"><select name="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);"<?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
We are adding the onchange event which will call the Javascript into action.

Also I would add

Code: Select all

<option value="">-- Please select --</option
Just below

Code: Select all

<td width="80%"><select name="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);"<?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
-Steve
plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

hm. Still no go. I reread myself many times...may still be a typo or something. Perhaps it would be easier if you could see it from my site? plecavalierDOTcom/help

...I'll keep hacking away at it regardless. Thanks!
steve
Posts: 147
Joined: Tue Mar 27, 2012 9:32 pm

Re: Conditional Dropdown Boxes

Post by steve »

I dont want to sound like a broken record, but you do realize that all these instructions have been for adding conditional drop down boxes to the ADMIN interface, not the customer interface right? The steps and code will be simillar, but the files you need to edit are different.

To accomplish this for the customer interface you would need to edit hesk/index.php

Also, the drop down boxes are static, its the options that are conditional.
-Steve
plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

steve wrote:I dont want to sound like a broken record, but you do realize that all these instructions have been for adding conditional drop down boxes to the ADMIN interface, not the customer interface right?
oh! I didn't know that. Might explain why I'm not seeing what I think I should be ;) ...funny(and slightly frustrating)
steve wrote: The steps and code will be simillar, but the files you need to edit are different.

To accomplish this for the customer interface you would need to edit hesk/index.php
Perfect. I'll re-apply.
steve wrote:Also, the drop down boxes are static, its the options that are conditional.
Yep. I get that.

Thanks Steve!
plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

ahhh. Do the right thing get the expected results...What a concept :)

Thanks again Steve, I appreciate the help.
plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

Alright, I kinda thought(as I'm sure you did to) I'd be stuck here...

When I choose a root category the appropriate sub-category appears. From there most of my "flowchart" contains a sub-set of categories. How do I call that array? I'm assuming I'll need to give the sub-cats a unique id somehow and call an associated sub-category script to populate to?!
steve
Posts: 147
Joined: Tue Mar 27, 2012 9:32 pm

Re: Conditional Dropdown Boxes

Post by steve »

So you want conditional drop down boxes from conditional drop down boxes?

Like I said in an earlier post, this code should be enough for you to peice it together.

I dont have tiime right now to provide you with the code, I also want the same functionality for my site so Ill have a look at it next week. Ill let you know when I get it done, till then, let us know if you get it figured out by yourself and share the code to save me some time :D
-Steve
plc
Posts: 89
Joined: Wed Jun 20, 2012 2:09 pm

Re: Conditional Dropdown Boxes

Post by plc »

No worries. Whomever gets it done posts for the rest of us...
dr_patso
Posts: 192
Joined: Tue May 15, 2012 3:23 am

Re: Conditional Dropdown Boxes

Post by dr_patso »

i'm going to start messing with this, YAY.

one thing I'm curios about: I'm going to try and implement entire custom fields populating based on what category is selected, all the custom fields are hand coded from your directions to force population and or selection of custom fields... what if I want a field to be REQUIRED but it also only populates per certain category's.. when I hide the required custom field because the selected category does not require it, will i still get an error since it's not populated?? Or will it go just fine because that required custom field isn't addressed at all in the submission?

well time to start digging, I love all your help Steve.. The tools is great enough as it is but this feature will help me clean up some categories and look smart.
steve
Posts: 147
Joined: Tue Mar 27, 2012 9:32 pm

Re: Conditional Dropdown Boxes

Post by steve »

Let me make sure I understand you:

You are going to have lets say 5 condition drop down boxes total, but some categories will only use 4 (or three of whatever) therefor leaving one not selected? And you are wondering if that will cause an error?

You will get errors for non populated fields, that's the whole idea right :lol:

I think we can work around this, lets see what you come up with and we will go from there.

BTW
What do you mean by "when I hide the required custom field"?
-Steve
dr_patso
Posts: 192
Joined: Tue May 15, 2012 3:23 am

Re: Conditional Dropdown Boxes

Post by dr_patso »

sorry for any confusion!

I'm as far as getting the subcategory drop downs to populate according to the category ID... I want entire custom fields to drop based on the category selected.

for a simple start let's say, the entire subcategory drop down you made goes away entirely for a handful of category's selected... you have 10 categories and only need the subcategory drop down for 2 or 3.

anyway, I haven't spent any time playing with how you have it working... but it is working, now just to create javascript cases that have an entire custom field showing up or not instead of just values in a field.
steve
Posts: 147
Joined: Tue Mar 27, 2012 9:32 pm

Re: Conditional Dropdown Boxes

Post by steve »

So by drop you mean remove, you want to show/hide custom fields based on the category selected?

What an idea!

Let me know how that goes, If I don't hear anything from you, ill start looking into this during the week.
-Steve
dr_patso
Posts: 192
Joined: Tue May 15, 2012 3:23 am

Re: Conditional Dropdown Boxes

Post by dr_patso »

ya, by drop I mean hide.. example: if category ID 4 is selected a custom field appears.. much like your values in the drop down.. This will clean up some categorys

off to googles!
dr_patso
Posts: 192
Joined: Tue May 15, 2012 3:23 am

Re: Conditional Dropdown Boxes

Post by dr_patso »

been cracking at this all day...

just above category I have this javascript


Code: Select all

	<script language="javascript" type="text/javascript">
	function test() {
    if (document.getElementById('category').value == '1') {document.getElementById('custom1').style.display = 'block';} 
	if (document.getElementById('category').value == '1') {document.getElementById('space1').style.display = 'block';} 
	if (document.getElementById('category').value == '1') {document.getElementById('sntext').style.display = 'block';} 
	}

	</script>

the category calls this script on change

Code: Select all

	<td width="80%"><select id="category" name="category" onchange='test()' <?php if (in_array('category',$_SESSION['iserror'])) {echo ' class="isError" ';} elseif (in_array('category',$_SESSION['isnotice'])) {echo ' class="isNotice" ';} ?> >
	<option value="">-- Please select --</option>

This is all for one field so far "serial number"

Code: Select all

<tr>
  <td style="display: none" id="sntext" width="150"><?php echo $hesklang['serialn']; ?>:</td>
  <td width="80%" id="space1" style="display: none"><input type="text" id="custom1" name="custom1" style="display: none" size="40" maxlength="25" value="<?php if (isset($_SESSION['as_custom1'])) {echo stripslashes(hesk_input($_SESSION['as_custom1']));} ?>"Autocomplete="off"/></td>
  </tr>

This works in a sense.. if I use an ELSE statement, I can't have the custom field showing up for other selected categories, so I would have to code all category IDs that I don't want to have the custom field in there to not "block" but to "display: none"

This all would work for me so far, except when I select category 1 the field comes back but not aligned.. argh...

not sure how this would play out with required fields, but optional fields it should work, if I can just figure out how to align it.... or maybe a javascript that doesn't change the style of a form but hides a whole section of code...
Post Reply