Monday, June 27, 2011

Chronoforms

Last couple of days was working on Chronoforms a Joomla extension used to create forms. I found something interesting as compared to other form extensions.
Using the form wizard one can create form easily, but you need to make change in form designing to fit the look of your form to the site. This is quite tedious task(atleast for me). Most things i like about the chronoform is the ability to setup the email & email template. You can execute bit of php code any time you want like before form submit, after form submit, before mail send, after mail sent. If you wanna store form details in database, chronoform provides ability to create table. I would to suggest, should use chronoform whenever email setup & email templates has higher priority. At the end its free.
Whenever need to create forms in joomla, you should have to think of Chronoforms.

Thursday, June 16, 2011

How to Create Joomla Select Box

How to create select box in joomla.
Simple Select box

$names = array(0 => "Select Name", 1 => 'Amit', 2 => 'Amit', 3 => 'Ajeet', 4 => 'Amar');
$options = array();
foreach($names as $key=>$value)
{
$options[] = JHTML::_('select.option', $key, $value);
}
$simple_dropdown = JHTML::_('select.genericlist', $options, 'name', 'class="inputbox"', 'value', 'text');
echo $simple_dropdown;

In joomla development, many time you need to show dynamic select box with the values from database.
Joomla drop down with values from database

$db = JFactory :: getDBO();
$query = "select * from #__users";
$db->setQuery($query);
$result = $db->loadObjectList();
$options = array();
$options[] = JHTML::_('select.option', '0', 'Select Name');
foreach($result as $row)
{
$options[] = JHTML::_('select.option', $row->id, $row->name);
}
$dropdown = JHTML::_('select.genericlist', $options, 'class="inputbox"', 'name', 'value', 'text');
echo $dropdown;

To select default option
$default = 62; // make sure this value must match
$dropdown = JHTML::_('select.genericlist', $options, 'class="inputbox"', 'name', 'value', 'text', $default);
echo $dropdown;

To use radio button instead of dropdown
$radio = JHTML::_('select.radiolist', $options, 'class="inputbox"', 'name', 'value', 'text', $default);
echo $radio;

To use radio button with newline.
add this line
$radio =str_replace('</label>','</label><br />', $radio); before echo $radio;
You can read more here.

Thursday, June 2, 2011

Best way to calculate the difference between date time

As a developer we always need to compare dates(with time or without) & get the no. of days, years, weeks, hours, minutes, seconds according to the requirement. So that why shoudn't a function which does all these. With the help of this function you can get the difference between two dates or times very easily. Whole code is written in php.