• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

setting up form validation and captcha in asp. net storefront (topic forms)

Im working with the asp. net store front platform and trying to get captcha and validation funcionality to work on a form that is a topic.  I can get both the captcha (recaptcha) and the validation (javascript) to work out side of the store front, but when they are put into the store front environment they dont work.  has any one dealt with this, just looking for some answers and hopefully some example of how you got it to work
<script type="text/javascript">
 
function formValidator(){
	// Make quick references to our fields
	var Name = document.getElementById('Name');
	var Phone = document.getElementById('Phone');
	var Email = document.getElementById('Email');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(Name, "The Name field is required and must be filled out")){
	if(notEmpty(Phone, "The Phone field is required and must be filled out")){
	if(notEmpty(Email, "The Email field is required and must be filled out")){
	if(isAlphabet(Name, "Please enter only letters for your name")){
		if(isNumeric(Phone, "Numbers Only for Phone")){
						if(emailValidator(Email, "Please enter a valid email address")){
							return true;
						}
					}
				}
				}
				}
				}
	
	return false;
	
}
 
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}
 
function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9-]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
 
function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z' ']+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
 
function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
    </script>
 
            If you would like to contact a specific store, <b><a href="t-locations.aspx" target="_self">
                click here</a></b> for location contact information.</span></span><br>
    <hr size="1">
    <b>Or, use the form below to send us a message</b><br>
    <br>
    <form id="FORM1" onsubmit="return formValidator()" action="sendform.aspx">
    <div align="left">
        <table border="0" cellspacing="0" cellpadding="0" width="454">
            <tbody>
                <tr>
                    <td valign="top" width="102" align="right">
                        Your Name:
                    </td>
                    <td valign="center" width="348" align="left">
                        <input size="27" name="Name">
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="102" align="right">
                        Your Phone:
                    </td>
                    <td valign="center" width="348" align="left">
                        <input size="27" name="Phone">
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="102" align="right">
                        Your E-Mail:
                    </td>
                    <td valign="center" width="348" align="left">
                        <input size="27" name="Email">
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="102" align="right">
                        Subject:
                    </td>
                    <td valign="center" width="348" align="left">
                        <input size="27" name="Subject">
                    </td>
                </tr>
                <tr>
                    <td valign="top" width="102" align="right">
                        Message:
                    </td>
                    <td valign="center" width="348" align="left">
                        <textarea name="S1" cols="41" rows="11"></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="102">
                    </td>
                    <td width="348">
                        <input type="submit" value="Submit" onclick="return formValidator()" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    </form>

Open in new window

0
batracy
Asked:
batracy
1 Solution
 
mwhitworthCommented:
This is an ASP.NET question, ye might be better off asking in that forum.
0
 
mathieu_cuprykCommented:
call this :
            <TD><IMG src="CaptchaImage.aspx" /></TD>

this is the CatchaImage.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;

public partial class CaptchaImage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Random Rand = new Random();
        int iNum = Rand.Next(10000, 99999);
        Bitmap Bmp = new Bitmap(90, 50);
        Graphics Gfx = Graphics.FromImage(Bmp);
        Font Fnt = new Font("Verdana", 12, FontStyle.Bold);
        Gfx.DrawString(iNum.ToString(), Fnt, Brushes.Yellow, 15, 15);
        // Create random numbers for the first line
        int RandY1 = Rand.Next(0, 50);
        int RandY2 = Rand.Next(0, 50);

        // Draw the first line
        Gfx.DrawLine(Pens.Yellow, 0, RandY1, 90, RandY2);
        // Create random numbers for the second line
        RandY1 = Rand.Next(0, 50);
        RandY2 = Rand.Next(0, 50);
        // Draw the second line
        Gfx.DrawLine(Pens.Yellow, 0, RandY1, 90, RandY2);
        Bmp.Save(Response.OutputStream, ImageFormat.Gif);
        Session["Number"] = iNum;


    }
}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CaptchaImage.aspx.cs" Inherits="CaptchaImage" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
</body>
</html>
0
 
batracyAuthor Commented:
I apologize for the lateness of this reply - the person working on this left the company and I was not aware that he had a question up.

We will try this solution when we have a chance.  Thank you, mathieu.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now