• Resolved Igor S.

    (@arsenique)


    Hi there,

    I’m adding a two-choice radio button to the advert form using adverts_form_load filter and so far everything is fine and working. However, I need the first of these two buttons selected by default. So, this is what I have so far:

    function eec_yes_or_no( $form ) {
    if( $form[“name”] != “advert” ) {
    return $form;
    }

    $form[“field”][] = array(
    “name” => “eec_yes_or_no”,
    “type” => “adverts_field_radio”,
    “order” => 25,
    “label” => “Yes or no”,
    “is_required” => true,
    “max_choices” => 1,
    “options” => array(
    array(“value”=>”1”, “text”=>”Yes”),
    array(“value”=>”2”, “text”=>”No”),
    ),

    );

    return $form;
    }

    Any pointers on how to check “Yes” by default?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    to set the default value for a field you would need to use a bind function for example like this

    
    add_filter( "adverts_form_bind", "eec_yes_or_no_bind" );
    function eec_yes_or_no_bind( $form ) {
        if( ! adverts_request( "eec_yes_or_no" ) ) {
            $form->set_value( "eec_yes_or_no", "1" );
        }
        return $form;
    }
    
    Thread Starter Igor S.

    (@arsenique)

    Hi Greg,

    Thanks!
    Works like a charm ??

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom radio button checked by default’ is closed to new replies.