Help - Search - Members - Calendar
Full Version: Form Mail Required Field Code
MonsterSmallBusiness Forums > MonsterCommerce > How do I?
flyerhut.com
Does anyone know how to make a field required using the Form Mail program that monstersmile.gif provides for custom HTML pages?

Also, how to make it so that have to enter a proper email address.

Thanks in advance!
krazykickz
You can do this with javascript, however it takes quite a few lines of code, it was a pain in the rear trying to code it. (but that is me as a intermediate scripter)
undejj
This is a script that I use to validate the email (and also require it). I hijacked this script from my own MC site and modified it slightly to suit my needs. You could use this script and modify it to fit your needs. If you need help, PM me with the details (copy of your form, etc.)

CODE
<script language="javascript">
function validateEmail(txtEmailAddress, btnSubmit)
{
 if (document.getElementById(txtEmailAddress).value.length > 0)
   {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById(txtEmailAddress).value))
  {
   document.getElementById(btnSubmit).disabled=1; //valid email
  }
  else
  {
      alert('The Email Address You Entered Is Invalid. Please Try Again!');
      document.getElementById(txtEmailAddress).focus();
      return false;
  }
 }else
 {
  alert('Please enter a valid email address');
  document.getElementById(txtEmailAddress).focus();
  return false;
 }
}
</script>


This is how I call the script within a form:

CODE
<INPUT TYPE=text NAME="txtEmailAddress" id="RequestEmail" value="" size=45>
<input TYPE="SUBMIT" NAME="btnSubmit" id="Sub1" VALUE="Send Request">
flyerhut.com
I tried the code but it didn't work, is there any specific place I should put it?
undejj
QUOTE (flyerhut.com @ Jun 25 2004, 02:33 PM)
...is there any specific place I should put it?

Well, no, not really. Put the script anywhere on the page where you are calling it. Perhaps you could post your form so that we could see what is going wrong ..

For example, do your INPUT fields have the same names as those that I posted earlier?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.