FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JS Validation
#1
I have tryed to get JS validation working on my forms but all that happens when I click submit is the alert box pops up telling me what to fix and then if I just click submit again without fixing anything the form passes validation and gets submitted.
There must be a trick that I am missing. I followed the documentation and it validates once then if you just submit the form a second time, the form just submits without running the validation.
How do you "reset" the form so that it will run the validation each time it gets submitted?
Here are my rules.
var rules = [];
rules.push("required,year,Please enter the year of your car.");
rules.push("required,make,Please enter the make of your car.");
rules.push("required,model,Please enter the model of your car.");
rules.push("required,body,Please enter the body style of your car.");
rules.push("required,name,Please enter your name.");
rules.push("required,work_phone,Please enter your work phone.");
rules.push("required,home_phone,Please enter your home phone.");
rules.push("required,city,Please enter your city.");
rules.push("required,email,Please enter your email address.");
rules.push("valid_email,email,Please enter a valid email address.");
rules.push("required,claim,Are you going to file an insurance claim?.");

rsv.errorFieldClass = null;
rsv.customErrorHandler = null;
rsv.displayType = "alert-all";

Here is my form "action":
<form action="<?php echo FORM_PROCESSOR; ?>" method="POST" onsubmit="return rsv.validate(this, rules)">

(the PHP code allows me to run the same form on mutiple machines without hard coding the path to the Form Processor application)

Please let me know if you have any ideas as I am now way behind schedule with the project of getting our forms to work with your Form Processor application.
Reply
#2
One other thing. I just wanted you to know that your Contact Demo has this same issue. I went there hopping that I could notice if I left something out by looking at the source code, but when I tested that demo form, it also validated once and on a second submit it never ran the validation.
Reply
#3
Huh... weird. It works okay for me and the code you posted looks totally fine.

What browser & OS are you running? It's possible I introduced a bug somewhere...

[Edit] - I just checked it over on FF 3.6 & Safari (Mac). I'll try it on my PC browsers when I get home.

- Ben
Reply
#4
(Jan 30th, 2010, 10:41 AM)Ben Wrote: Huh... weird. It works okay for me and the code you posted looks totally fine.

What browser & OS are you running? It's possible I introduced a bug somewhere...

[Edit] - I just checked it over on FF 3.6 & Safari (Mac). I'll try it on my PC browsers when I get home.

- Ben


Ben my OS is Windows XP and browser is IE 7. I did test your demo Contact us page in Firefox and it worked correctly. It must be an IE issue. I'll have to figure out something to get it to work in IE as my site is public and I can't control what they use to access it.
If you think of anything that I can do to get the validation to work as it does in Firefox let me know.
Thanks again for getting back with me.
Reply
#5
Good grief! This is actually a bug - I'm extremely surprised!!! I've been using this script for years... this was a problem I introduced in the last update.

I'll include a fix for it in the next FT release, but in the meantime you can just manually update your /global/scripts/rsv.js file.

Go to line 623. There you'll see the rsv.styleField function:

Code:
rsv.styleField = function(field, focus)
{
  // if "field" is an array, it's a radio button. Focus on the first element
  if (field.type == undefined)
  {
    if (focus)
      field[0].focus();

To fix it, just change those lines to this (I've added in two extra lines):

Code:
rsv.styleField = function(field, focus)
{
  if (!rsv.errorFieldClass)
      return;

  // if "field" is an array, it's a radio button. Focus on the first element
  if (field.type == undefined)
  {
    if (focus)
      field[0].focus();

Then, you'll probably need to empty IE's cache. IE can cache files - even after you update them on the server, which makes like a real pain for us developers.

That should fix the problem.

Thanks SO much for reporting this, I'm really quite surprised!

- Ben
Reply
#6
(Jan 30th, 2010, 10:46 PM)Ben Wrote: Good grief! This is actually a bug - I'm extremely surprised!!! I've been using this script for years... this was a problem I introduced in the last update.

I'll include a fix for it in the next FT release, but in the meantime you can just manually update your /global/scripts/rsv.js file.

Go to line 623. There you'll see the rsv.styleField function:

Code:
rsv.styleField = function(field, focus)
{
  // if "field" is an array, it's a radio button. Focus on the first element
  if (field.type == undefined)
  {
    if (focus)
      field[0].focus();

To fix it, just change those lines to this (I've added in two extra lines):

Code:
rsv.styleField = function(field, focus)
{
  if (!rsv.errorFieldClass)
      return;

  // if "field" is an array, it's a radio button. Focus on the first element
  if (field.type == undefined)
  {
    if (focus)
      field[0].focus();

Then, you'll probably need to empty IE's cache. IE can cache files - even after you update them on the server, which makes like a real pain for us developers.

That should fix the problem.

Thanks SO much for reporting this, I'm really quite surprised!

- Ben

Ben - thanks for taking the time to help me out. Your fix solved the issue and I can get back to work getting all of my forms changed over to use your form processor.
Reply
#7
Good to know! I've logged this as a bug - it'll be fixed in the next beta.
http://bugs.formtools.org/index.php?cmd=view&id=193

- Ben
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)