Form Validation

Getting it working

Page 1 of 1

9 Replies - 1640 Views - Last Post: 19 September 2007 - 07:34 PM

#1 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Form Validation

Posted 14 September 2007 - 03:28 PM

Alright, and..what's the problem you're having?
Is This A Good Question/Topic? 0
  • +

Replies To: Form Validation

#2 Arbitrator   User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 530
  • Joined: 26-January 05

Re: Form Validation

Posted 15 September 2007 - 05:46 AM

View Postretmsg21, on 14 Sep, 2007 - 05:16 PM, said:

I am attempting to validate my form requiring users to fill out all the boxes and alert them if they don't:
I can tell you right now that your document contains numerous basic errors. I suggest that you add the required document type declaration [1] and validate your code [2]. I’d personally recommend the HTML 4.01 Strict doc. type declaration:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html401/strict.dtd">


Some of your errors include:
  • a missing doc. type declaration (as just mentioned).
  • having three body start tags and two head end tags.
  • using SGML comment tags (<!-- and -->) within a [icode]script[/icode] element.
  • having more than one title elements.
  • using the b element within the head element.
  • putting FORM in the middle of the form element start tag.
  • putting a non‐URI inside of the action attribute. (mailto: is needed.)
  • missing tr elements.
  • using a table element for layout instead of to associate data.
  • using the invalid absmiddle value for the align attribute.
There are several more errors that will show themselves in a validator when using a Strict DTD. These mainly force you to exercise good practice, such as using CSS instead of presentational attributes and elements.

I suggest that you fix all of this and come back.

Was This Post Helpful? 0
  • +
  • -

#3 retmsg21   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 10-December 06

Re: Form Validation

Posted 17 September 2007 - 06:36 PM

I am attempting to get the form to validate that the user is entering information into the form and I am pulling what hair I have left out.

<HTML>
<HEAD>
<TITLE>Kudler Fine Foods</TITLE>
</HEAD>
<BODY>
<body bgcolor="#ffaaff">

<script LANGUAGE="javascript">

function validInput()
{
   if (Home.First.value=="")
{
alert ("Last Name Field Needs a value")
}
Elseif (home.last.value==””)
}
alert ("First Name Field Needs a value")
}
Elseif (home.address.value==””)
}
alert ("Address Field Needs a value")
}
Elseif (home.City.value==””)
}
alert ("City Field Needs a value")
}
Elseif (home.State.value==””)
}
alert ("State Field Needs a value")
}
Elseif (home.Area.value==””)
}
alert ("Area Code Field Needs a value")
}
Elseif (home.Phone.value==””)
}
alert ("Phone Number Field Needs a value")
}
Elseif (home.Email.value==””)
}
alert ("Email Field Needs a value")
{

alert("Good")
}
}

</script>

var currLoc = document.referrer

function parseForm()  {

<!-- Open and launch confirmation form-->

var valform = "Confirmation_Page.html "

myWindow = window.open(valform)

}

function getBack() {

	 history.go(-1)

}

</SCRIPT>


<b><TITLE>Kudler Fine Foods</TITLE></b>

<BODY BGCOLOR=#FFFFFF LINK=#0000FF VLINK=#FF0000 ALINK=#800080>

<CENTER><H1>Kudler Fine Foods</H1></CENTER>

<CENTER><H2>Kudler Fine Foods Promotions Sign Up Form</H2></CENTER>
<HR>

<form enctype="text/plain" FORM METHOD=POST ACTION="mailto:[email protected]" NAME="Home" onsubmit=parseForm()>

<!-- Creating the form layout-->

<TABLE>
<TD>Please enter the following Information:</TD>
<TR><TD>Last Name:</TD>

<TD><INPUT NAME="Last" TYPE="text" VALUE="" SIZE="30"></TD><TD>First Name:</TD>

<TD><INPUT NAME="First" TYPE="text" VALUE="" SIZE="30"></TD></TR>

<TR><TD>Street address:</TD>

<TD><INPUT NAME="Address" TYPE="text" VALUE="" SIZE="30"></TD></TR>

<TR><TD>City:</TD><TD><INPUT NAME="City" TYPE="text" VALUE="" SIZE="30">

<TD>State:</TD><TD><INPUT NAME="State" TYPE="text" VALUE="" SIZE="10"></TD></TR>

<TR><TD>Area Code:</TD>

<TD><INPUT NAME="Area" TYPE="text" VALUE="" SIZE="5"></TD><TD>Phone Number:</TD>

<TD><INPUT NAME="Phone" TYPE="text" VALUE="" SIZE="10"></TD></TR>

<TR><TD>Please enter your email address:</TD>

<TD><INPUT NAME="email" TYPE="text" VALUE="" SIZE="30"></TD></TR>

</TABLE>

<BR><BR>

<INPUT NAME="Submit" type="submit" VALUE="Submit" ALIGN=top> 

<INPUT NAME="reset" type="reset" value="Reset" ALIGN=absbottom>


</FORM>

 </BODY>
 </HTML>


*added code tags*

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 asadarnell   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 108
  • Joined: 30-August 07

Re: Form Validation

Posted 17 September 2007 - 07:57 PM

Code tags please.

This post has been edited by asadarnell: 17 September 2007 - 07:58 PM

Was This Post Helpful? 0
  • +
  • -

#5 retmsg21   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 10-December 06

Re: Form Validation

Posted 17 September 2007 - 09:18 PM

View Postasadarnell, on 17 Sep, 2007 - 07:57 PM, said:

Code tags please.



Code tags please???? :angry:
Was This Post Helpful? 0
  • +
  • -

#6 supersssweety   User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: Form Validation

Posted 18 September 2007 - 10:51 AM

I think your problem lies here:
<form enctype="text/plain" FORM METHOD=POST ACTION="mailto:[email protected]" NAME="Home" onsubmit=parseForm()>


you are not telling the form to validate, you are sending it straight to the parseForm function, how is it supposed to access that code if you don't send it to the validInput function?
Was This Post Helpful? 0
  • +
  • -

#7 ahmad_511   User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: Form Validation

Posted 18 September 2007 - 01:45 PM

Hi every one
supersssweety you're right, but believe me there is more

1-take a look at this

Quote

Elseif (home.last.value==””)
}
alert ("First Name Field Needs a value")
}


Ok this will not work, as you can see there is closed brace } after elsif and it should be open brace {
elseif should be else if and with small letters

2- and another thing

Quote

function parseForm()  {
<!-- Open and launch confirmation form-->



This is not the way you comment inside javascript
You need touse this
// this way you can add one line comment in javascript
/* and this is
The way 
You can 
Comment multiple lines 
*/



3-Beware of case sensitive

Quote

Elseif (home.last.value==””)


The name of the form is Home not home
The last name field's name is Last not last

4-Now let's talk about some logical things

Quote

if (Home.First.value=="")
{
alert ("Last Name Field Needs a value")
}



So if the first name field was empty alert that the last name needed!!??

Another thing
What if some fields are empty and you are alerted by the validate function, so the submit action will continue… (Because you didn't stop it after you detect the missing fields)

So what you have to do in my opinion is to change the onsubmit event to onclick event and then when validation done you can submit the whole form
<form enctype="text/plain" FORM METHOD=POST ACTION="mailto:[email protected]" NAME="Home" onclick= validInput()>



Now on the validate function
Home.submit()
alert("Good")



I don't have time to try it so try it your self and reply us if it works or not
Regards

This post has been edited by ahmad_511: 18 September 2007 - 01:47 PM

Was This Post Helpful? 0
  • +
  • -

#8 supersssweety   User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: Form Validation

Posted 18 September 2007 - 01:51 PM

View Postahmad_511, on 18 Sep, 2007 - 01:45 PM, said:

Hi every one
supersssweety you're right, but believe me there is more


Wow yes there was much MUCH more, I didn't even hardly look at the script lol I always look for the simple stuff first. Good catch on all of those things! I knew you weren't getting anywhere without calling it.
Was This Post Helpful? 0
  • +
  • -

#9 Arbitrator   User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 530
  • Joined: 26-January 05

Re: Form Validation

Posted 19 September 2007 - 10:33 AM

I’ve noticed that obvious issues like <form enctype="text/plain" FORM METHOD=POST ACTION="mailto:[email protected]" NAME="Home" onclick= validInput()> still haven’t been fixed or mentioned by anyone else. (Why is the word form in the tag twice?) Another obvious issue: this person has a </script> tag in the middle of their script.

Such issues can be easily caught be a validator like the one at http://validator.w3.org/. Maybe retmsg21 should try using one.
Was This Post Helpful? 0
  • +
  • -

#10 Thorian   User is offline

  • Pirate Medic
  • member icon

Reputation: 22
  • View blog
  • Posts: 5,904
  • Joined: 06-June 02

Re: Form Validation

Posted 19 September 2007 - 07:34 PM

Thanks for the heads up Arbitrator I merged the valid points from that post with this one and deleted the original thread
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1