• Resolved susananova

    (@susananova)


    Hi Greg,

    Is it possible to add some code snippet to add a simple checkbox (mandatory to check) which makes the user have to agree with the Terms and Conditions before posting the ad?

    Many thanks

    The page I need help with: [log in to see the link]

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

    (@gwin)

    Hi, with some custom programming this is possible, here https://wpadverts.com/documentation/custom-fields/ you can find a code snippet explaining how to add a new Checkbox field to the Adverts Add form, you will need to customize it a bit to remove the text field and make the checkbox required, so your function will look somewhat like this

    
    function my_adverts_form_load( $form ) {
        if( $form["name"] != "advert" ) {
            return $form;
        }
    
        $form["field"][] = array(            
            "name" => "my_custom_checkbox",
            "type" => "adverts_field_checkbox",
            "order" => 25,
            "label" => "Custom Checkbox",
            "is_required" => false,
            "validator" => array( array( "name" => "is_required" ) ),
            "max_choices" => 2,
            "options" => array(
                array("value"=>"1", "text"=>"One"),
                array("value"=>"2", "text"=>"Two"),
            )
        );
        
        return $form;
    }
    
    Thread Starter susananova

    (@susananova)

    Hi Greg,

    I′ve tried the following but is not working at all, what am I missing?

    add_filter( "adverts_form_load", "my_adverts_form_load" );
    function my_adverts_form_load( $form ) {
        if( $form["name"] != "advert" ) {
            return $form;
        }
    
        $form["field"][] = array(            
            "name" => "my_custom_checkbox",
            "type" => "adverts_field_checkbox",
            "order" => 25,
            "label" => "Termos e Condi??es",
            "is_required" => true,
            "validator" => array( 
                array("name"=>"is_required", "text"=>"Declaro que li e aceito os Termos e Condi??es do Trabalhitos"),
            )
        ); 
        return $form;
    }
    Plugin Author Greg Winiarski

    (@gwin)

    What do you mean by “not working at all”? The field does not show in the form or it shows but is not required?

    Additionally, your code is incorrect in the “validator” option and it is missing the “options” it should be

    
    add_filter( "adverts_form_load", "adverts_add_tos" );
    function adverts_add_tos( $form ) {
        if( $form["name"] != "advert" ) {
            return $form;
        }
    
        $form["field"][] = array(            
            "name" => "my_custom_checkbox",
            "type" => "adverts_field_checkbox",
            "order" => 25000,
            "label" => "Terms and Conditions",
            "is_required" => true,
            "validator" => array( 
                array( 
                    "name"=>"is_required", 
                    "default_error" => "You have to agree to terms and conditions" 
                ),
            ),
            "options" => array(
                array( 
                    "value" => 1, 
                    "text" => "I agree to terms and conditions" 
                )
            )
        ); 
    
        return $form;
    }
    
    Thread Starter susananova

    (@susananova)

    Amazing Greg, now it works great.
    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add checkbox to “Agree to T&C” on add ads page’ is closed to new replies.