CF v4 custom server side validation

marklandry 08 Nov, 2011
Hi,
I had the following custom validation in v3 that worked fine:

<?php
if($_POST['text_0'] > 20)
return 'Sorry, you cannot score more than "20" in the STAR Game.  Please enter a score of 20 or less';
?>


I'm now trying to make it work in version 4 but having no luck:

<?php
if ($_POST['text_0'] > 20) {
  $form->validation_errors['text_0'] = "Sorry, you cannot score more than 20 in the STAR Game.  Please enter a score of 20 or less";
  return false;
}
?>


Thanx in advance for your help
GreyHead 08 Nov, 2011
Hi Mark,

That looks OK to me. Please post a link to the form so I can take a quick look.

Bob
GreyHead 08 Nov, 2011
Hi Mark,

Do you have an Event Loop action in the OnFail event?

Bob
marklandry 08 Nov, 2011
I do now,
That did it,
thanx!!

Mark
marklandry 08 Nov, 2011
well,

Now if I post something higher than 20 (ie a value that kicks off the validation message)
A value of "0" is posted to the database, which will really throw off the component that uses the info from the db.

Anything I can do to keep if from posting if the value is not allowed?

Thanx again.

Mark
GreyHead 08 Nov, 2011
Hi Mark,

Have the Serverside validation action before the DB Save action?

Bob
marklandry 08 Nov, 2011
also,
If I enter an incorrect captcha, I get the error message from the custom validation code.
How can I configure it to say "incorrect captcha?"
GreyHead 08 Nov, 2011
Hi Mark,

Have the Check Captcha (with its Event Loop action in the OnFail event) before the Server Side validation action.

Bob
marklandry 08 Nov, 2011

Hi Mark,

Have the Serverside validation action before the DB Save action?

Bob



It is...
GreyHead 08 Nov, 2011
Hi Mark,

Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
marklandry 08 Nov, 2011
I put a "show stopper" event in the custom validation on fail event and that seemed to do the trick.
Thanx again for all of your help!

Mark
GreyHead 08 Nov, 2011
Hi Mark,

If you have an Event Loop in there you shouldn't need the Show Stopper as well.

Bob
marklandry 08 Nov, 2011
nope - that's not it..
Took the show stopper out and now it miraculously works...
I probably need to just walk away from this for a bit
marklandry 08 Nov, 2011
A new prob...
My first form is called "skills_star"
It is one of multiple forms that I have on a single page
If I copy skills_star, call it something else, change settings etc,
the new form and skills_star will show a "incorrect captcha" error no matter what you put in the fields.

If I make a new form as opposed to copying a form, it works,
But I really need to be able to copy or this will take forever.
GreyHead 09 Nov, 2011
Hi Mark,

If you have multiple forms on the same page then the form names and all the input names and ids must be unique.

Bob
marklandry 09 Nov, 2011
Still doesn't seem to be working if I copy a form.
The skills_star form has input id and name text_0
the skills_ladder form has input id and name text_1

Again, if I create the form from scratch it works fine.
GreyHead 09 Nov, 2011
Hi Mark,

Hmmm . . . a bit baffled here. It may be something about the way Max has set up the Captcha in CFv4 that doesn't get re-set when you copy.

Bob
marklandry 09 Nov, 2011
I'll play around with it - maybe delete the captcha, save, clear cache, add it back in, etc...
I'll let you know.
Thanx
Mark
This topic is locked and no more replies can be posted.