Articles Tagged 'form'

Customizing a Form graphically

I was asked how to customize a graphical form, in particular a search box like the one on this blog. The technique used, or rather that I use, is obviously valid for any type of module form. What changes is only the complexity of the work to be done depending on the complexity of the form itself.

Continued ...

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 - eye on the site of the proposed indications WordPress . When you make a HTML form with a SUBMIT button must be careful not to set the name of the input tag just "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 you try to run at a 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 it what you will but not the button "submit"!

The code I used to display 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 ) ; $ To = 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'>". __ ('Name'). "</ option> \ n";
$categories ) { if ($ categories) {
$categories as $category ) { foreach ($ categories as $ category) {
apply_filters ( 'list_cats' , $category -> cat_name , $category ) ; $ Cat_name = apply_filters ('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 chosen category reload the page when I have time ... just look at him better.

As known to all, for the sake of completeness, I note that action was needed with a non-intrusive code (Unobtrusive) instead of entering directly into the construction of the onchange of the combo. In addition, 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 ;) .

Continued ...