Concrete5.7 : Javascript validation for a block’s form

If you are developing a block for Concrete 5.7 you might be looking for the Javascript function ‘ccmValidateBlockForm’ that handles the clientside validation of your block’s form. It seems to have dissappeared in Concrete 5.7 which leaves you with no way to prevent the form from being submitted if it contains validation errors.

I ran into this problem recently as I was developing my own block. The wrong approach is to listen to a form submit event. I tried this but discovered it submitted anyway as Concrete was triggering a submit with Javascript. The trick is to prevent that script from being triggered. Concrete listens to a click on the form’s submit button which is in fact not a submit button but an anchor using Javascript to trigger the click event on the real submit button which is hidden from sight.

This is how to solve it:

 

Replace ‘myFormValidationFunction’ with the name of your function that validates the form. Return false to prevent the form from submitting or true to allow it to submit.

Published by

Justin

Justin

Hi there! I'm a software engineer currently employed at a company in The Hague in the Netherlands. You can find out more about me and my qualifications on LinkedIn (http://nl.linkedin.com/pub/justin-van-schaick/26/1b0/210). I started this blog in order to share interesting code snippets and tutorials on mainly Javascript, PHP and related frameworks. The internet is an invaluable resource for programmers and unfortunately there's never enough documentation out there. So this is me trying to contribute to that.

Leave a Reply