Dynamically Selecting Default Option on a Dropdown Menu Dynamically Selecting Default Option on a Dropdown Menu
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Dynamically Selecting Default Option on a Dropdown Menu

Started by jeepguy_1980, March 17, 2009, 07:16:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jeepguy_1980

I modified the sort cell in a theme I picked up from DaMysterious. I made it into a drop down menu so that the text wouldn't run off of the top of the table.  I would like to know how I can setup my drop down menu to automatically select the default sort order that I have in my CPG configuration.

Thank you.


// HTML template for title row of the thumbnail view (album title + sort options)
if (!isset($template_thumb_view_title_row)) { //{THEMES}
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="4" cellspacing="0">
                        <tr>
                                <td width="100%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
                                <td><img src="images/spacer.gif" width="1" alt="" /></td>
                                <td class="sortorder_cell">
<form name="sort">
<select name="sortbox" OnChange="location.href=sort.sortbox.options[selectedIndex].value">
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=ta">{TITLE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=td">{TITLE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=na">{NAME} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=nd">{NAME} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=da">{DATE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=dd">{DATE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pa">{POSITION} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pd">{POSITION} -</option>
</select>
</form>
                               
                                </td>
                        </tr>
                        </table>

EOT;
}  //{THEMES}

jeepguy_1980

I changed it to this for now:


// HTML template for title row of the thumbnail view (album title + sort options)
if (!isset($template_thumb_view_title_row)) { //{THEMES}
$template_thumb_view_title_row = <<<EOT

                        <table width="100%" cellpadding="4" cellspacing="0">
                        <tr>
                                <td width="100%" class="statlink"><h2>{ALBUM_NAME}</h2></td>
                                <td><img src="images/spacer.gif" width="1" alt="" /></td>
                                <td class="sortorder_cell">
<form name="sort">
<select name="sortbox" OnChange="location.href=sort.sortbox.options[selectedIndex].value">
<option>Sorting Order</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=ta">{TITLE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=td">{TITLE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=na">{NAME} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=nd">{NAME} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=da">{DATE} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=dd">{DATE} -</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pa">{POSITION} +</option>
<option value="thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=pd">{POSITION} -</option>
</select>
</form>
                                                                </td>
                        </tr>
                        </table>

EOT;
}  //{THEMES}


Joachim Müller

Perform a check against $CONFIG['default_sort_order']
Don't forget to make that array global first inside a function.
Are you actually populating the placeholder tokens in theme_display_thumbnails() or is above code just wishfull thinking?

jeepguy_1980


Thanks, I'll give that a try.

Quote from: Joachim Müller on March 18, 2009, 07:34:13 AM
Are you actually populating the placeholder tokens in theme_display_thumbnails() or is above code just wishfull thinking?


The code works exactly as I hoped.  See here: www.loopfamily.net/CPG/  You can see it work on any gallery.


Joachim Müller

Works as expected, thanks. Looks promising - you might consider to post your entire mod for the benefit of others.

jeepguy_1980

That is my entire mod, with the exception of a slight change I made to the stylesheet.css to get the drop down menu to line up a bit cleaner.

I have never written anything in PHP and don't know anything about it.  I am willing to post this mod to help others, but I would first like to make it display the sorting order used (i.e. the default sort order).

I have tried using the following code to display the the default sort order, but it's not working.


<form name="sort">
$sortarr = Array("ta","td","na","nd","da","dd","pa","pd");
$i = 1;
echo "<select name=\"sortbox\" size=1 OnChange=\"location.href=sort.sortbox.options[selectedIndex].value\">";
while($i !=  8){
     $r = mysql_fetch_array($CONFIG['default_sort_order']);
     if($r['default_sort_order'] == $sortarr[$i]){
          $selected = "selected";
            }
     else{
          $selected = "";
            }
     echo "<option value=\"thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=.$sortarr[$i].\" ".$selected.">".$sortarr[$i]."</option>";
     $i++
     }
     echo "</selected>";
</form>

Joachim Müller

It can not possibly work because it contains syntax errors - you're mixing HTML and PHP, which is something you can't do. Haven't looked at your code, but echo '<form name="sort">';
$sortarr = Array("ta","td","na","nd","da","dd","pa","pd");
$i = 1;
echo "<select name=\"sortbox\" size=1 OnChange=\"location.href=sort.sortbox.options[selectedIndex].value\">";
while($i !=  8){
     $r = mysql_fetch_array($CONFIG['default_sort_order']);
     if($r['default_sort_order'] == $sortarr[$i]){
          $selected = "selected";
            }
     else{
          $selected = "";
            }
     echo "<option value=\"thumbnails.php?album={AID}&amp;page={PAGE}&amp;sort=.$sortarr[$i].\" ".$selected.">".$sortarr[$i]."</option>";
     $i++
     }
     echo "</selected>";
echo '</form>';
should at least stop the syntax errors. Please post the entire code, not just snippets.