[html-formfu] pre-checked radio button

Carl Franks fireartist at gmail.com
Thu Nov 1 15:32:35 GMT 2007


On 01/11/2007, kewei xiao <kewei.xiao at nald.ca> wrote:
> Thanks for the hint,
> for some reason, when I use fill_formfu_values, it only fills some
> value, so instead, I am using $form->get_field('')->default;

It'd be very helpful it you'd provide more info about what causes
fill_formfu_values() to fail.
* the column name and type (definition)
* the field name and type and other settings
* the relevant value in the database

> so for the radio button case, i was doing like this:
>
> if ( $rs->item_id ) {
>     $form->get_field('radioButton')->default( 'checked' );
> }

A Radio button is either On (checked) or Off (unchecked).
It should always have the value() set to something. This is what the
browser submits if the Radio button is checked.

It only makes sense to set default() to the same string as value().
If default() equals value(), then the Radio button gets checked="checked".
If they're not the same, it doesn't.

To summarize:

    ---
    elements:
      - type: Radio
        name: foo
        value: 'my-value'

then...

    if ( $rs->item_id eq 'my-value' ) {
        $radiobutton->default('my-value');
    }

Hope this clears things up,
Carl



More information about the HTML-FormFu mailing list