[RESOLVED] Have 'Please Select' in custom dropdown field?

Everything related to Hesk - helpdesk software

Moderator: mkoch227

Post Reply
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

[RESOLVED] Have 'Please Select' in custom dropdown field?

Post by Raven »

Hi, could you please advise how I can have '- Please Select -' as my initial value in the dropdown custom fields code:

Code: Select all

/* Select drop-down box */
	            case 'select':
					echo '
					<tr>
					<td valign="top" style="text-align:right" width="150"><p>'.$v['name'].': '.$v['req'].'</p></td>
	                <td width="80%"><select name="'.$k.'">';

	            	$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;
Thanks
Last edited by Raven on Sat Oct 17, 2009 6:59 pm, edited 1 time in total.
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

This is for the category, but works on the same principle:
viewtopic.php?t=2612
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
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

Post by Raven »

I understand what code to add as you kindly pointed me to one of my previous posts. However, I do not know where to add the '<option value="">- Select -</option>' part.

If I put it at the end of <td width="80%"><select name="'.$k.'">'; like so it doesn't work:

Code: Select all

	            /* Select drop-down box */
	            case 'select':
					echo '
					<tr>
					<td valign="top" style="text-align:right" width="150"><p>'.$v['name'].': '.$v['req'].'</p></td>
	                <td width="80%"><select name="'.$k.'"><option value="">- Select -</option>';

	            	$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;
Any pointers?
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

Post by Raven »

I have also tried replacing '<option '.$selected.'>'.$option.'</option>' with '<option '.$selected.'>- Please Select -</option>' and '<option value="" '.$option.'>- Please Select -</option>' but none of the above seem to work :(

It is prob something really stupid that I'm missing too lol

I know how to add '<option value="" >- Please Select -</option>' to a standard form but with all the other php code I'm a little lost...
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Try again the code you posted, but also remove

Code: Select all

strlen($k_value) == 0 || 
from the if sentence.
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
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

Post by Raven »

Hi Klemen, thank you for your suggestion. Just to be sure, is this what you mean>?

Code: Select all

               /* Select drop-down box */
               case 'select':
               echo '
               <tr>
               <td valign="top" style="text-align:right" width="150"><p>'.$v['name'].': '.$v['req'].'</p></td>
                   <td width="80%"><select name="'.$k.'"><option value="">- Select -</option>';

                  $options = explode('#HESK#',$v['value']);

                   foreach ($options as $option)
                   {

                     if $k_value == $option)
                      {
                          $k_value = $option;
                           $selected = 'selected="selected"';
                      }
                       else
                       {
                          $selected = '';
                       }

                      echo '<option '.$selected.'>'.$option.'</option>';
                   }

                   echo '</select></td>
               </tr>
               ';
               break; 
If so, will it still produce an error if - Select - is left as the selection by detecting the empty value=""?
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

This is it, yes, give it a try. And it should produce an error if this optional field is a required one.
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
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

Post by Raven »

Hi there, I have tested the last lot of code but it seems that when I alter this bit: 'if $k_value == $option)' it fails... Give me a syntax error and the whole page fails to display.
Klemen
Site Admin
Posts: 10136
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

You ahve a "(" missing before $k_value. It should be

Code: Select all

if ($k_value == $option)
Don't delete anything but the code I mentioned.
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
Raven
Posts: 172
Joined: Sat Jun 20, 2009 12:39 am

Post by Raven »

Ahh, I missed that :oops:

I now have the following code and it works a treat - thank you :)

Code: Select all

	            /* Select drop-down box */
	            case 'select':
					echo '
					<tr>
					<td valign="top" style="text-align:right" width="150"><p>'.$v['name'].': '.$v['req'].'</p></td>
	                <td width="80%"><select name="'.$k.'"><option value="">- Please Select -</option>';

	            	$options = explode('#HESK#',$v['value']);

	                foreach ($options as $option)
	                {

		            	if ($k_value == $option)
		                {
	                    	$k_value = $option;
	                        $selected = 'selected="selected"';
		                }
	                    else
	                    {
	                    	$selected = '';
	                    }

	                	echo '<option '.$selected.'>'.$option.'</option>';
	                }

	                echo '</select></td>
					</tr>
					';
	            break;
Also within 'hesk_style.css' I have added this:

Code: Select all

select {
	width: 262px;
	font-size: 12px;
	height: 20px;
}
This also allows me to define the width, font and height so that the select dropdown matches the rest of the other text boxes.

Just an idea, but in each custom fields options might it be possible to have an area to add a style too sort of like: 'style="width: 262px;"' or anything the Admin needs - this would save having to edit the main hesk_style.css file and allow an easier implentation for custom CSS?
Post Reply