Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: incrediBILL

Message Too Old, No Replies

HTML form validation - html form code

How to ensure users type the correct responses

     

dakiddddd

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>
<div>*Email:<input type="text" name="email" size="25" maxlength="140"/>
</div>
<div>*Phone Number: <input type="text" name="phone" size="25" maxlength="140"/>
</div>
<div>Company:<input type="text" name="Company" size="25" maxlength="140"/>
</div>
<div>*Website Address: <input type="text" name="URL" size="25" maxlength="140"/>
</div>
<div>Monthly Budget:<input type="text" name="Bugget" size="25" maxlength="140"/>
</div>
<div>How did you find us?<input type="text" name="Bugget" size="25" maxlength="140"/>
</div>
<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>
</select>
</div>
<div align="left">Owner?
<select name="ownership">
<option value="own">Yes</option>
<option value="do not own">No</option>
</select>
</div>
<div align="left">Your Goal: <div>
<textarea name="comments" rows="6" cols="35">
</textarea>
</div>
</div>
<div align="left">
<input type="submit" name="Request" value="submit"/>
<input type="reset" name="Clear" value="clear form"/>
</div>
</form>
</div>
</div>

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?

lucy24

4:28 am on Sep 4, 2011 (gmt 0)

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



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.

phranque

5:51 am on Sep 4, 2011 (gmt 0)

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



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.

rocknbil

4:10 pm on Sep 6, 2011 (gmt 0)

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



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.

dakiddddd

4:37 pm on Sep 7, 2011 (gmt 0)



Will try everything here. Thank you guys.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month