Page 1 of 1
[RESOLVED] Have 'Please Select' in custom dropdown field?
Posted: Fri Oct 09, 2009 4:11 pm
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
Posted: Fri Oct 09, 2009 4:15 pm
by Klemen
This is for the category, but works on the same principle:
viewtopic.php?t=2612
Posted: Fri Oct 09, 2009 9:05 pm
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?
Posted: Fri Oct 09, 2009 11:14 pm
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...
Posted: Sat Oct 10, 2009 4:48 pm
by Klemen
Try again the code you posted, but also remove
from the if sentence.
Posted: Sat Oct 10, 2009 6:15 pm
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=""?
Posted: Sun Oct 11, 2009 8:43 am
by Klemen
This is it, yes, give it a try. And it should produce an error if this optional field is a required one.
Posted: Sun Oct 11, 2009 1:16 pm
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.
Posted: Sun Oct 11, 2009 2:20 pm
by Klemen
You ahve a "(" missing before $k_value. It should be
Don't delete anything but the code I mentioned.
Posted: Sun Oct 11, 2009 3:36 pm
by Raven
Ahh, I missed that
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?