0

I the osclass When I post listing, choosing a city is not required. How can I make it required ? When I select city, it shows in the post, but I also can post listing without selection the city, but I want the city to be required.

Aht CreW
  • 3
  • 2
  • 1
    Do you have any code you can show? It's usually as simple as adding a `requried` attribute to the `` http://www.w3schools.com/tags/att_input_required.asp – Mike Lyons Mar 25 '15 at 20:37

1 Answers1

0

You have two ways to do it:

1- Hook method

Using the pre_item_post (osclass < 3.3) or pre_item_add (osclass >=3.4).

osc_add_hook("pre_item_add", function($aItem) {
    if($aItem["city"] !== "") {
        osc_add_flash_error_message(_e("Please select a city", "your_theme"));
        $this->redirectTo(osc_item_post_url());
    }
});

2- Javascript method

Using jQuery Validate, like in Bender theme.

$('.form-horizontal').validate({
    rules: {
        region: {
            required: true
        },
        city: {
            required: true
        }
    },
    messages: {
        region: {
            required: "Please select a region"
        },
        city: {
            required: "Please select a city"
        }
    }
});
Hussard
  • 656
  • 7
  • 14