This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

yanto.lee40371
yanto.lee40371

Would like to find out if it is possible to programatically validate a component's properties on save when a particular component is added to layout/page? Thanks

Briddle
Briddle

Hi,

Components can have multiple properties and those properties can have validation rules (and also default values).

At a minimum a component will have an input called 'Alias' that cannot be empty, e.g. if you click on the component and empty the alias field a red notification will immidiately popup.

More info in the docs here: https://octobercms.com/docs/plugin/components#component-properties

yanto.lee40371
yanto.lee40371

Briddle said:

Hi,

Components can have multiple properties and those properties can have validation rules (and also default values).

At a minimum a component will have an input called 'Alias' that cannot be empty, e.g. if you click on the component and empty the alias field a red notification will immidiately popup.

More info in the docs here: https://octobercms.com/docs/plugin/components#component-properties

Hi Briddle, Thank for pointing out on the default validation rules, but what I am trying to do is to allow user to input content with html tag into the property hence I will need to do manual validation for XSS injection prior saving it. any idea on that? Or maybe other approach to do it instead of doing it as properties? Thanks

Briddle
Briddle

Hi,

Ok, I am not completely clear on what you mean. The only people who can add a component to a page or layout are backend-users (users of the CMS) not website users. Am I correct to understand that you are talking about external properties for components? Instead of using the component like this:

{% component 'myComponent' %}

You can do this:

{% component 'demoTodoAlias' maxItems='7' %}

See: https://octobercms.com/docs/cms/components

What are we talking about?

  • website users, frontend users (User plugin by RainLab) or backend users (users of the CMS)
  • What information do you want to collect from them (you mentioned html but what for?)
  • What do you want to do with this information (retrieve info from the database or write info to the database)

Maybe you should be using a form (https://octobercms.com/docs/services/html#opening-a-form)?

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.