migglesuuportcontact us

web design and development, content management & media



Jargon-free guidance on creating hard-working business and e-commerce websites; the latest from miggle's Brighton and Hove web design studio; web development news - subscribe to this feed

Article Suggestion
If there's a topic you would like miggle to write about please use the box above.

Posts Tagged ‘TDO mini forms’

miggle

Using TDO Mini Forms with WordPress to create an interactive website.

7th June, 2010 by Ian

At miggle we have recently started a project using WordPress. The client wanted their users to be able to make posts from the front-end without needing WordPress logins. After many searches we found TDO Mini Forms (http://wordpress.org/extend/plugins/tdo-mini-forms/). A very highly customizable plugin – perfect as a starting point for our goal.

TDO Mini Forms has two main options:

  • Form Creator – Where you setup your form fields.
  • Form Hacker – Where you have more control to customize the form fields.

One function the client wanted was a drop down list where users could select their location.

When setting up the drop down list through the form creator, it only allows you to include X amount of categories by putting their IDs. This was good to start with but what happens if we want to add more categories? We would need to update the form every time, adding in the new category ID.

This was not ideal for us – We needed the locations drop down list to be dynamic. Over to the TDO Mini form hacker!

With PHP and WordPress’s wp_dropdown_categories() function we can pull in the categories dynamically.

Quick Tip:

Here is the updated code to pull in categories from a category parent.

<p><select name=’location' class='tdomf_location' size='1'>
<option value="1"<?php if( (is_array($defcat) && in_array(1, $defcat)) || ( 1 == $defcat ) ) { echo ' selected="selected" '; } ?>>Please Select</option>

<?php
/*
Setup our dropdown arguments.
The arguments allow us to get the child elements of our parent (location)
With a depth of 1 e.g. if we had parent > child > grandchild it would only get our child level.
*/

$args = array(
'echo' => 0,
'hide_empty' => 0,
'child_of' => 5,
'orderby' => 'name',
'style' => 'none',
'hierarchical' => 1,
'depth'  => 1
);
// Create the drop down list
$select = wp_dropdown_categories( $args );
// Only pull out the <option.....></option> tag (remove <select…></select>)
$select = strip_tags($select, "<option>");
// Display results on the screen
echo $select;
?>
</select>

By using this method our client can continue to add or delete categories allowing the drop down list to dynamically update without needing to update the TDO Mini form’s creator as well.

Based in Brighton and Hove, East Sussex, contact miggle.co.uk for website development, content management and online media services in the UK and worldwide.

 
miggle