close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Client Validation - Restrict Content not working?

Thread began 11/20/2012 6:12 am by Nathon Jones Web Design | Last modified 11/20/2012 1:45 pm by Nathon Jones Web Design | 1054 views | 5 replies

Nathon Jones Web Design

Client Validation - Restrict Content not working?

We have two simple client validations on our form, one to check that caption text has been entered for a title (form field name="slideshowtitle") and one to check that neither http:// or https:// has been entered in a URL (form field name="slideshowlinkout"). The URL field can, however, be left blank.

The validation is working for the caption text - a value must be entered - however the URL field is allowing submission of http:// and/or .

Here's our form:

<form action="confirm-slideshow.asp" method="post" enctype="multipart/form-data" name="addslideshowFORM" id="addslideshowFORM" onsubmit="WAValidateRQ(document.forms[0].slideshowtitle,'You need to enter some text to accompany your image.',document.forms[0].slideshowtitle,0,true,'text');WAValidateRT(document.forms[0].slideshowlinkout,document.forms[0].slideshowlinkout.value,'You do not need to enter http:// or https:// in your website address.','%20http://%20|, %20https://%20|',document.forms[0].slideshowlinkout,0,false);WAAlertErrors('Please correct the following errors:','',true,document.addslideshowFORM,false);return document.MM_returnValue">
<input name="aID" type="hidden" id="aID" value="<%=cStr(Request.Form("aID"))%>" />
<input name="gID" type="hidden" id="gID" value="<%=cStr(Request.Form("gID"))%>" />

<div>
<label for="slideshowtitle">Caption text for the image:</label>
<input name="slideshowtitle" id="slideshowtitle" type="text" size="25" maxlength="100" tabindex="1" />
</div>

<div>
<label for="slideshowlinkout">Web address the image should link to: <span class="textgrey">(optional)</span></label>
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="8%" class="textgrey">http://</td>
<td valign="middle"><input name="slideshowlinkout" id="slideshowlinkout" type="text" size="25" maxlength="75" tabindex="2" /></td>
</tr>
</table>
</div>

<div>
<label for="slideshowimg">Select an image (500px x 375px - <a href="help-imagesizes.asp">Image Guidelines</a>):</label>
<input name="slideshowimg" type="file" id="slideshowimg" style="height:35px;width:450px;background-color:#FFFFFF;" tabindex="3" />
</div>

<p><input type="submit" name="Submit" value="Proceed" class="Submitbtn" tabindex="4" /></p>
</form>

...and here is our validation code:

<script type="text/javascript">
<!--
function WAtrimIt(theString,leaveLeft,leaveRight) {
if (!leaveLeft) {
while (theString.charAt(0) == " ")
theString = theString.substring(1);
}
if (!leaveRight) {
while (theString.charAt(theString.length-1) == " ")
theString = theString.substring(0,theString.length-1);
}
return theString;
}

function WAFV_GetValueFromInputType(formElement,inputType,trimWhite) {
var value="";
if (inputType == "select") {
if (formElement.selectedIndex != -1 && formElement.options[formElement.selectedIndex].value && formElement.options[formElement.selectedIndex].value != "") {
value = formElement.options[formElement.selectedIndex].value;
}
}
else if (inputType == "checkbox") {
if (formElement.length) {
for (var x=0; x<formElement.length ; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (formElement.checked)
value = formElement.value;
}
else if (inputType == "radio") {
if (formElement.length) {
for (var x=0; x<formElement.length; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (formElement.checked)
value = formElement.value;
}
else if (inputType == "radiogroup") {
for (var x=0; x<formElement.length; x++) {
if (formElement[x].checked && formElement[x].value!="") {
value = formElement[x].value;
break;
}
}
}
else if (inputType == "iRite") {
var theEditor = FCKeditorAPI.GetInstance(formElement.name) ;
value = theEditor.GetXHTML(true);
}
else {
var value = formElement.value;
value=value.replace(/<p>(\&\#160\;)*<\/p>/,"");
}
if (trimWhite) {
value = WAtrimIt(value);
}
return value;
}

function WAAddError(formElement,errorMsg,focusIt,stopIt) {
if (document.WAFV_Error) {
document.WAFV_Error += "\n" + errorMsg;
}
else {
document.WAFV_Error = errorMsg;
}
if (!document.WAFV_InvalidArray) {
document.WAFV_InvalidArray = new Array();
}
document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
if (focusIt && !document.WAFV_Focus) {
document.WAFV_Focus = focusIt;
}

if (stopIt == 1) {
document.WAFV_Stop = true;
}
else if (stopIt == 2) {
formElement.WAFV_Continue = true;
}
else if (stopIt == 3) {
formElement.WAFV_Stop = true;
formElement.WAFV_Continue = false;
}
}

function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType) {
var isValid = true;
if (formElement.length && inputType.toLowerCase()!="radio" && inputType.toLowerCase()!="select") formElement=formElement[0];
if (!document.WAFV_Stop && !formElement.WAFV_Stop) {
var value=WAFV_GetValueFromInputType(formElement,inputType,trimWhite);
if (value == "") {
isValid = false;
}
}
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
}
}

function WAValidateRT(formElement,value,errorMsg,notAllowed,focusIt,stopIt,required) {
var isValid = true;
var augValue = " " + value + " ";
var tempVal = augValue.toLowerCase();
if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value=="")) {
var notAllowed = notAllowed.split(", ");
for (var x=0; x<notAllowed.length; x++) {
var notAllowedInfo = notAllowed[x].split("|");
notAllowedInfo[0] = unescape(notAllowedInfo[0]);
notAllowedInfo[1] = unescape(notAllowedInfo[1]);
while (tempVal.indexOf(notAllowedInfo[0].toLowerCase())>=0) {
isValid = false;
var theIndex = tempVal.indexOf(notAllowedInfo[0].toLowerCase())
tempVal = tempVal.substring(0,theIndex) + tempVal.substring(theIndex+notAllowedInfo[0].length);
if (notAllowedInfo[1]!="") {
theIndex = augValue.toLowerCase().indexOf(notAllowedInfo[0].toLowerCase())
augValue = augValue.substring(0,theIndex) + notAllowedInfo[1] + augValue.substring(theIndex+notAllowedInfo[0].length);
}
}
}
}
if (required && value=="")
isValid = false;
if (!isValid) {
WAAddError(formElement,errorMsg,focusIt,stopIt);
formElement.value = augValue.substring(1,augValue.length-1);
}
}

function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm,allowOverride) {
if (!document.WAFV_StopAlert) {
document.WAFV_StopAlert = true;
if (document.WAFV_InvalidArray) {
document.WAFV_Stop = true;
var errorMsg = document.WAFV_Error;
if (errorHead!="")
errorMsg = errorHead + "\n" + errorMsg;
if (errorFoot!="")
errorMsg += "\n" + errorFoot;
document.MM_returnValue = false;
if (document.WAFV_Error!="") {
if (allowOverride) {
if (confirm(errorMsg.replace(/&quot;/g,'"'))) {
document.MM_returnValue = true;
return;
}
}
else {
alert(errorMsg.replace(/&quot;/g,'"'));
}
}
else if (submitForm)
submitForm.submit();
if (setFocus && document.WAFV_Focus) {
if (document.getElementById(document.WAFV_Focus.name+"___Config") && document.WAFV_Focus.type.toLowerCase() == "hidden") {
var theEditor = FCKeditorAPI.GetInstance(document.WAFV_Focus.name);
theEditor.EditorWindow.focus();
setTimeout("setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1);
}
else {
document.tempFocus = document.WAFV_Focus;
setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1);
}
}
else {
document.WAFV_Stop = false;
document.WAFV_StopAlert = false;
}
for (var x=0; x<document.WAFV_InvalidArray.length; x++) {
document.WAFV_InvalidArray[x].WAFV_Stop = false;
}
}
else {
document.WAFV_Stop = false;
document.WAFV_StopAlert = false;
if (submitForm) {
submitForm.submit();
}
document.MM_returnValue = true;
}
document.WAFV_Focus = false;
document.WAFV_Error = false;
document.WAFV_InvalidArray = false;
}
}
//-->
</script>

Hope someone can spot the error as we've deleted and rebuilt the form 3 times now and are no further forward.

Thank you.
NJ

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...