homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

HTML form validation - html form code
How to ensure users type the correct responses

Msg#: 4358456 posted 2:40 am on Sep 4, 2011 (gmt 0)

Hi,I am a newbie who uses third party software to create websites. So I have this website and then i learned how to create a form. Never took html course so bare with me. The bits I know have brought me far. Only thing is I don't know how to make sure users enter the right responses. For example, in the email field, you can enter anything and submit it. I have no code or way to make sure it's actually an existing email. You can enter random numbers and still no validation. I'm not good at CSS so the challenge is, no CSS. I used a third party form software but it screws my W3C html validation. Any help? Any input pleease?

Here is the code:

<form method="post" action="http://www.mydom.com/cgi-bin/formmail.pl">
<input type="hidden" name="redirect" value="http://www.mydom.com/thankyoupage.html"/>
<input type="hidden" name="recipient" value="newsletter@mydom.com"/>
<input type="hidden" name="subject" value="Newsletter or quote"/>
<div>*Your Name:<input type="text" name="name" size="25" maxlength="100"/>
<div>*Email:<input type="text" name="email" size="25" maxlength="140"/>
<div>*Phone Number: <input type="text" name="phone" size="25" maxlength="140"/>
<div>Company:<input type="text" name="Company" size="25" maxlength="140"/>
<div>*Website Address: <input type="text" name="URL" size="25" maxlength="140"/>
<div>Monthly Budget:<input type="text" name="Bugget" size="25" maxlength="140"/>
<div>How did you find us?<input type="text" name="Bugget" size="25" maxlength="140"/>
<div align="right">*This request is to
<select name="request for">
<option value="newsletter">Join our newsletter</option>
<option value="quote">FREE quote </option>
<option value="quote">Call Back (specify time/goal box) </option>
<option value="other">Other (please specify below)</option>
<div align="left">Owner?
<select name="ownership">
<option value="own">Yes</option>
<option value="do not own">No</option>
<div align="left">Your Goal: <div>
<textarea name="comments" rows="6" cols="35">
<div align="left">
<input type="submit" name="Request" value="submit"/>
<input type="reset" name="Clear" value="clear form"/>

There is no way of validating any of my fields. How do i make sure the email address is actually an email address and that the website address is actually a website URL?



WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4358456 posted 4:28 am on Sep 4, 2011 (gmt 0)

Uhm, I hope you simply mean "correctly formatted" not "actually valid" because that takes you into a whole nother realm. You want something in the form blahblah at blahblah dot tld, and then something in the form {optional www.} blahblah dot tld, right?

Short answer: You cannot do it with html alone. But take heart: CSS won't do anything either; that's just for presentation.

Piece of cake in javascript, php or language of your choice. Betcha if you keep looking, you'll find a plugin that lets you constrain responses to a given format. Another common one is telephone numbers.

Oh, and if your generated html doesn't validate, find a different package.


WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Msg#: 4358456 posted 5:51 am on Sep 4, 2011 (gmt 0)

you can use Document Object Model Events:
http://www.w3.org/TR/DOM-Level-2-Events/events.html [w3.org]
(such as onchange, onselect, onsubmit) to trigger JavaScript Form Validation:
http://www.w3schools.com/js/js_form_validation.asp [w3schools.com]

this browser-side validation should help prevent the POST request from being sent until some reasonable input validation is executed.
you must also do similar and usually additional input validation and sanitizing in your form action script.


WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4358456 posted 4:10 pm on Sep 6, 2011 (gmt 0)

To add to that last bit - Javascript can be disabled, which means that no matter what you do client side via Javascript - which is actually an enhancement in the interest of the user, not a way to avoid abuse of your script - you'll have to duplicate that server side (I.E., within the receipt at "formmail.pl")

If this is the old script from M.S.A., I'd recommend changing over to NMS Form Mail (google it) which leads to a Pretty Good Answer to the validation question: the NMS formmail has pretty robust instructions on how to manage some of the form inputs, particularly email.


Msg#: 4358456 posted 4:37 pm on Sep 7, 2011 (gmt 0)

Will try everything here. Thank you guys.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved