Custom Block Validation.

Permalink
I am quite new to Concrete5. I am building a custom block for a website and I am following the tutorial onhttp://www.concrete5.org/documentation/how-tos/developers/understan...

I manage to save the block and display it, yet I am unable to find the solution to validation. I want to make certain fields required. Event though I can run the validation, using the validator helper, I am unable to display the errors.

 
joseajohnson replied on at Permalink Reply
joseajohnson
Without any more details, like maybe a code sample of your validation, it's hard to say - assuming the validator is loaded and 'errorMsg' and 'emptyIsOk' parameters defined, though, you should be able to grab errors with the following:

if ($val->test()) {
    // proceed...
} else {
    $errorArray = $val->getError()->getList(); 
    $this->set('errorArray', $errorArray); // send array to view (in a single_page for example)
}


The above is from here:
http://www.concrete5.org/documentation/developers/forms/basic-valid...

You could send some invalid input and shoot it out immediately with
var_dump($errorArray);

if your just looking to see what goes on, or
$errorHtml = $val->getError()->output(); 
echo $errorHtml;

to get some pretty HTML formatted results.
$errorHas = $val->getError()->has();

is a boolean reporting the presence of errors overall.

Hope this helps!
Mnkras replied on at Permalink Reply
Mnkras
you could use javascript, take a look at how some of the existing blocks do validation
jordanlev replied on at Permalink Reply
jordanlev
jaconel007 replied on at Permalink Reply
Thanks for the link. It was exactly what I was looking for. Got the validation hooked up in less than 5 mins.

Thank you for all the replies, very helpfull.