Articles Tagged 'submit'

WordPress: categories in the dropdown

I state that we are talking about WordPress 2.0.6. If you try to set the categories in "combo" - dropdown - watch out for signs proposed on the site of WordPress . When building an HTML FORM with a SUBMIT button must be careful not to set the name of the INPUT tag just to "submit," worth ruining everything just trying to submittare the FORM via Javascript.

On the site of WordPress is proposed the following code:

1
2
3
4
5
6
<li id="categories">
'Categories:' ) ; ?> <? Php _e ('Categories');?>
<li>
$PHP_SELF ?> " method="get"> <?php dropdown_cats ( ) ; ?> <input type="submit" name="submit" value="view" /> </form> <Form action = "<? Php echo $ PHP_SELF?>" Method = "get"> <? Php dropdown_cats ();?> <input Type="submit" name="submit" value="view" /> </ form>
</ Li> </ ul>
</ Li>

Note that the submit button has the name attribute set to "submit". If a try to the execute Javascript code like this:

1
. submit ( ) ; document. forms. nomeform. submit ();

The interpreter gets confused because it does not distinguish the method submit () element "submit", which is a button! The solution is simple: Call the button as you want but do not "submit"!

The code I used to see the categories in dropdown mode I is as follows:

1
2
3
4
5
<div id="cmb_months">
<form name="xcats" id="xcats" action="/index.php" method="get">
; ?> <? Php dropdown_cats ();?>
</ Form>
</ Div>

I also had to modify the kernel of WordPress (which should not be done ...). In the file "template-functions-category.php" I modified the function dropdown_cats () when preparing the SELECT TAG I added:

1
onchange = "document.forms ['xcats']. submit ();"

Here is the piece of code to track:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$wpdb -> get_results ( $query ) ; $ Categories = $ wpdb -> get_results ($ query);
. " \n " ; echo '<select name="cat" class="postform" onchange="document.forms[\'xcats\'].submit();">'. "\ n";
intval ( $optionall ) == 1 ) { if ( intval ($ optionall) == 1) {
apply_filters ( 'list_cats' , $all ) ; $ All = apply_filters ('list_cats', $ all);
<option value='0'>Seleziona una Categoria</option> \n " ; echo "\ t <option value='0'> Select a Category </ option> \ n";
}
intval ( $optionnone ) == 1 ) if ( intval ($ optionnone) == 1)
<option value='-1'>" . __ ( 'None' ) . "</option> \n " ; echo "\ t <option value='-1'>". __ ('None'). "</ option> \ n";
$categories ) { if ($ categories) {
$categories as $category ) { foreach ($ categories as $ category) {
apply_filters ( 'list_cats' , $category -> cat_name , $category ) ; Apply_filters cat_name = $ ('list_cats', $ category -> cat_name, $ category);
<option value= \" " . $category -> cat_ID . " \" " ; echo "\ t <option value= \"". $category -> cat_id. "\" ";
$category -> cat_ID == $selected ) if ($ category -> cat_id == $ selected)
; echo 'selected = "selected"';
; echo '>';
; echo $ cat_name;
intval ( $optioncount ) == 1 ) if ( intval ($ optioncount) == 1)
. $category -> cat_count . ')' ; echo '('. $ category -> cat_count. ')';
intval ( $optiondates ) == 1 ) if ( intval ($ optiondates) == 1)
. $category -> lastday . '/' . $category -> lastmonth ; echo ''. $ category -> lastday. '/'. $ category -> lastmonth;
" ; echo "</ option> \ n";
}
}
" ; echo "</ select> \ n";

One thing the function does is set the combo on the category you chose when you reload the page ... when I have time I look better.

As known to all, for the sake of completeness, I note that he must act with a non-intrusive code (Unobtrusive) instead of entering the onchange directly in the construction of the combo. Furthermore, the categories displayed in the combo are not accessible for browsers with Javascript disabled. However this can be solved by using the NOSCRIPT tag in the sidebar and view the categories as a list of links - default mode of WordPress - adjustments that will soon ;) .

More ...


Stop SOPA