Validations

Permalink
I'm kinda used to the mvc model. So I would like to know if there is any way to work in validation doing something to tell "field name can't be blank" or "field e-mail must be valid" other than using js. Like creating my own model, if it were a mvc application

View Replies:
andrew replied on at Permalink Reply
andrew
Unfortunately there's really no validation framework for blocks at this point. It'd be a good thing for us to add, certainly. We will put it on our to-do list. The javascript validation that blocks currently can use is sort of a stopgap solution.
AdrianoD replied on at Permalink Reply
I wanted to do a form, where I would ask searches for submiting their data, so we would have a database here, but I wanted to validate their phone numbers, e-mails, ids, so I guess the only way is javascript right ?
andrew replied on at Permalink Reply
andrew
If you really wanted a custom form for something like this, you could go outside the blocks and make what we call a "single page."

Check out this thread.

http://www.concrete5.org/index.php?cID=273...

I'd make a single page and then, make your form submit to:

<form method="post" action="<?=$this->action('save_information')?>">
</form>


And in your controller create the method save_information.

public function save_information() {
}


And you can do all sorts of validation stuff there. For example, this is how we handle registration, etc... If you want to see how we do stuff like that, check out

concrete/single_pages/register.php
concrete/controllers/register.php

We do a lot of validation, etc... there, before we save a user in the database.
Will replied on at Permalink Reply
Will
I cobbled together some functions from the guestbook block into the forms block like:
(!$v->email($_POST['email'])) {
               $errors['email'] = '- '.t("invalid email address");


but using it seems like the wrong approach. Not like I have any better ideas at the moment...
fr0z3nk0 replied on at Permalink Reply
what I do is I use Zend_Form.

I've created a block which allows you to specify fields and validation on them this then generates Zend_Form on which I simply call validate();

So basically in view of that block my form is a zend object on which I just call validate method.

something like this:
$form = $controller->getForm();
if (!empty($_POST)) {
if ($form->validate()) {
...
}
}

I've also implemented custom captcha...you can see it all here:
http://www.channellevents.com/contact_us/...
ScottC replied on at Permalink Reply
ScottC
i just plug in jquery's validation tool.

IN a single page you can name your form, so you do
a standard jquery document ready then $('#formName').validate());

each input then has the validation classes appended.

If you try to submit the form it attaches a label and returns false so the form doesn't submit.

Serverside, you should just use concrete5's validation helper, or alternatively Zend's.