We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31410
    • 66 Posts
    Hello
    i want to know is this possible to add multiple validation rules on same column of a table
    and if none of the rules satisfied it shud not save and if it satisfy anyone rule we allow it to save?
    like
    <validation>
    <rule field="name" name="invalidvideolink" type="preg_match" rule="/((|<a.*>?)http:\/\/([\\w+?\\.\\w+]+[a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\*\\(\\)_\\-\\=\\+\\?\\.\\:\\;\\\’\\,])\/watch\\?v=([-\\_!£$%^&*()+=,\\\\.?`¬|\\w]*)(<\/a>)?)/i" message="nvalid video link specified" />
    <rule field="name" name="invalidvideolink" type="preg_match" rule="/((|<a.*>?)http:\/\/[Vv][Ii][Dd][Ee][Oo]\\.[Gg][Oo][Oo][Gg][Ll][Ee]\\.(.*?)\/videoplay\\?docid=([-\\\\_!£$%^&*()+=,.\/?`¬|\\w]*).*)|<\/a>?/" message="Invalid video link specified" />
    </validation>

    i can do that in validation in code but curious about is this possible in xpdo validation

    some one give me wisdom plz smiley

    thax
      • 22303 MODX Staff
      • 10,725 Posts
      You can definitely define multiple rules per column; that is the point of the alias. As for the validation, you would need to run validation yourself and use the results to determine whether or not to save; the built-in xPDO::OPT_VALIDATE_ON_SAVE requires all validation rules to pass before saving, and the xPDOObject::validate() method returns false if any rule fails. In fact, I think you would have to process the rules yourself by providing your own xPDOValidator class that would handle this logic atm. However, I think the core xPDOValidator class could easily be refactored to provide the information you need (i.e. results per rule/alias instead of per column as it is now) if you would like to enter an improvement ticket at http://bugs.modx.com/projects/xpdo/issues