Revision [1008]

Last edited on 2009-01-10 12:50:35 by KlenwellAdmin
Additions:
'value'=>$RainbowList_value,
Deletions:
'value'=>'CA',


Revision [1007]

Edited on 2009-01-10 10:49:03 by KlenwellAdmin
Additions:
For converting a radio group to columns in ""CakePhp"". For more information, see http://www.klenwell.com/press/2009/01/cakephp-radio-select-columns/
Deletions:
For converting a radio group to columns in ""CakePhp"". For more information, see http://www.klenwell.com/press/2009/01/cakephp-radio-select-columnscakephp-radio-select-columns/


Revision [1006]

Edited on 2009-01-10 10:45:26 by KlenwellAdmin
Additions:
For converting a radio group to columns in ""CakePhp"". For more information, see http://www.klenwell.com/press/2009/01/cakephp-radio-select-columnscakephp-radio-select-columns/
Deletions:
For converting a radio group to columns in ""CakePhp"". For more information, see link


Revision [1005]

Edited on 2009-01-10 10:27:25 by KlenwellAdmin
Additions:
For converting a radio group to columns in ""CakePhp"". For more information, see link
for usage in the view file
print $klenwellForm->options_to_table(
$form->input( 'Model.field2', array(
'type'=>'radio',
'legend'=>$legend,
'value'=>'CA',
'before' => $klenwellForm->before_marker,
'after' => $klenwellForm->after_marker,
'separator' => $klenwellForm->separator_marker,
'options' => $RainbowList,
)
),
$num_cols=3
);
Deletions:
For more information, see link


Revision [1004]

Edited on 2009-01-10 10:25:40 by KlenwellAdmin
Additions:
class KlenwellFormHelper extends Helper
{
var $name = 'klenwellForm';

var $before_marker = '';
var $after_marker = '';
var $separator_marker = '';

var $table_class = 'klenwell-option-table';
function options_to_table($input, $num_cols=2)
{
/* Converts an input list into a table. Requires before, after, and
separator options be set like so:

print $klenwellFormHelper->input_to_table(
$form->input('Model.field', array('type'=>'radio',
'legend'=>'Label',
'value'=>$selected_value,
'before' => $klenwellFormHelper->before_marker,
'after' => $klenwellFormHelper->after_marker,
'separator' => $klenwellFormHelper->separator_marker,
'options'=>$Model->field_options));
);
*/

// slice up form input method output at markers
// sanity check
if ( strpos($input, $this->before_marker) === false ||
strpos($input, $this->after_marker) === false ||
strpos($input, $this->separator_marker) === false )
{
trigger_error('unable to convert list to table, missing before, after, or between marker', E_USER_WARNING);
return $this->output("\n{$input}");
}

// get top, bottom, and middle chunks
list($top, $trunk) = explode($this->before_marker, $input);
list($middle, $bottom) = explode($this->after_marker, $trunk);

// get option list
$OptionList = explode($this->separator_marker, $middle);
$num_options = count($OptionList);

// cakephp doesn't cooperate with its before and after placement so we
// have to do some tweaks here
$ftag1 = '
';
$ftag2 = '
';
$legend_regex = '%.*%U';

if ( strpos($OptionList[0], $ftag1) !== false )
{
$OptionList[0] = str_replace($ftag1, '', $OptionList[0]);
$top .= $ftag1;
}
if ( $legend = preg_match($legend_regex, $OptionList[0], $Match) )
{
$OptionList[0] = str_replace($Match[0], '', $OptionList[0]);
$top .= $Match[0];
}
if ( strpos($OptionList[$num_options-1], $ftag2) !== false )
{
$OptionList[$num_options-1] = str_replace($ftag2, '', $OptionList[$num_options-1]);
$bottom = $ftag2 . $bottom;
}

// divvy options into columns (wrote this code a while ago and seems to work)
for( $i = 1; $i <= $num_cols; $i++ )
{
$COL[$i] = ceil( $num_options/($num_cols+1-$i) );
$num_options = $num_options - $COL[$i];
}

// add tags to columns
$opt_num = 0;
$table_cells = '';
foreach ( $COL as $n => $num_in_col )
{
$col_list = '';
while( $num_in_col > 0 )
{
$col_list .= "
  • {$OptionList[$opt_num]}
  • \n";
    $num_in_col--;
    $opt_num++;
    }

    $table_cells .= <<

      $col_list


    XHTML;
    }

    // build table
    $middle = <<

    $table_cells


    XHTML;

    // reassemble complete element
    $output = << $top
    $middle
    $bottom
    XHTML;

    // return
    return $this->output($output);
    }
    }
    ?>


    Revision [1003]

    The oldest known version of this page was created on 2009-01-10 10:24:37 by KlenwellAdmin
    Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki