View Full Version : not validating on client side
watercolor346374
10-10-2010, 06:26 AM
Hello,
I am using the validation tools for client side validation. This is a simple form that allows one to add recipes to a recipe site. I am using includes ie: the main file is recipe.php and other files associated with the recipe section are inc files. I have used this tool before with ecart and it worked like a gem, now it will not validate this form. This file is newrecipe.inc.php and it posts to addrecipe.inc. php. When I click submit it goes to addrecipe.inc.php, no validation on blank fields. The info that is added to newrecipe is posted to the database. I have submitted my file.
Thank you
Jason Byrnes
10-12-2010, 08:15 AM
for some reason the regular exprtession validation function was not added to the script tag in the head.
add the following code to the script in the head to define the regular expresion validation:
function WAValidateRX(formElement,inputType,regExStr,errorM sg,focusIt,stopIt,required) {
var isValid = true;
var value=WAFV_GetValueFromInputType(formElement,input Type,required);
var extraArgs = regExStr.substring(regExStr.lastIndexOf("/")+1);
regExStr = regExStr.substring(regExStr.indexOf("/")+1,regExStr.lastIndexOf("/"));
regExStr = regExStr.replace(/"/g,'"');
var regEx = new RegExp(regExStr,extraArgs);
if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value=="")) {
var theMatch = regEx.test(value);
if (!theMatch) {
isValid = false;
}
}
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
}
}
watercolor346374
10-12-2010, 10:58 AM
Thank you, I did as you said and the script still goes through without validation. I sent along the script with the added lines.
Thank you
Jason Byrnes
10-12-2010, 11:11 AM
it works when I test your page on my system.
Does the main page this one is being included into have a form on it? if so you will need to replace each form reference:
document.forms[0]
with:
document.forms[1]
watercolor346374
10-12-2010, 11:48 AM
The main page that this is included in is barebones: recipe.php
<?php
session_start();//starts the session cookie
?>
<?php
include("mylibrary/showrecipe.php");
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Recipe</title>
<link href="kshotz.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="header">
<?php include("header.include.php");
?>
</div>
<div id="nav">
<div align="center"><?php include('navbar.include.php'); ?></div>
</div>
<div id="leftsidebar"><?php include('recipenav.include.php'); ?>
</div>
<div id="main">
<div class ="content"><?php if (!isset($_REQUEST['content'])) include("mainrecipe.inc.php");
else
{
$content = $_REQUEST['content'];
$nextpage = $content . ".inc.php"; include($nextpage);
}
?>
</div>
<div class="rightsidebar">
<div class="lastview">
<?php include("lastview.inc.php");
?>
</div>
</div>
</div>
<div id="footer">
<?php include("footer.include.php");
?>
</div></div>
</body>
</html>
There is a page that shows specific recipes and it does have an addcomment, that links to the addcomment.inc.php include. addcomment.inc.php and newrecipe.inc.php are included into recipe.php. Would this make a difference?
Also, changed the document forms to 1 and still does not work.
Jason Byrnes
10-13-2010, 12:44 PM
can you send a link where I can see the problem so I can investigate the cause.
watercolor346374
10-14-2010, 07:41 AM
Hi Jason,
Here is the link:
http://kshotz.com/recipe.php?content=newrecipe
the main url is kshotz.com then go to recipies and then add a new recipe.
Thank you,
K
Jason Byrnes
10-14-2010, 08:05 AM
there are 2 other forms on this page before the main one you are validating.
change each instance of:
document.forms[0]
to:
document.forms[2]
watercolor346374
10-14-2010, 10:55 AM
Hi Jason,
Making progress with this. I looked at the script and some major stuff was not added correctly. IE- instead of the correct variable for each form variable they all had: document.forms[2].title
So I changed it,now I get validation on all text but not for the drop downs. I checked them to old scripts that work and made the changes, but did not work. I am including the script and the link is http://kshotz.com/recipe.php?content=newrecipe
This is very strange that so much was left out when I ran the wizard, it has always worked.
Thank you,
K
Jason Byrnes
10-14-2010, 01:17 PM
you have regular expression validations applied to this form that are missing the regular expression to use.
go to Window -> Behaviors to open the behaviors list.
Select the first form element in design view, then select the Form tag from the tag selector.
In the behaviors window, double click each of the regular expression validations to correct them.
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.